Jef! 发表于 2022-7-6 00:49:56

Ok, i've made some new tests today. Since I had points in my grades.txt, I find&replaced every points just to be sure they were not the cause of my issue. I even removed all the "-", to keep only letters, digits and parenthèses. It still didn't work. I've put the readit and the retrieving function in the same lsp file (singletest.lsp) containing
(defun readit ( txt / des lst str )   (if       (and         (setq txt (findfile txt))         (setq des (open txt "r"))       )       (progn         (while (setq str (read-line des))               (setq lst (cons (read str) lst))         )         (close des)         (reverse lst)       )   ))(defun c:test ()(setq templst (readit "c:\\grades.txt")))
The file is not empty, and is in CADs support file search path list
Command: (findfile "grades.txt")"\\\\server\\project\\_drawing dept\\jef\\script\\grades.txt"I definitly got something tho. I tried as you said

(read (strcat "(" importedgradelist ")"))and it returned nothing (!) but reacted otherwise when I used the same function with a string I created.
 
Definitly am onto something here... OMGGGGGGI just found the 2 problems.1 - in my grades.txtI had a parentheses imbalance, 1 more opening than what I had closing. My baaaad, sooorry! Parentheses. If you don't like them, don't lisp! ok. still c:test didn't work..
 
2- (setq templst (readit "c:\\grades.txt")) seemed weird. Looking for it on my c: drive maybe? It is not, and the findfile does the job of finding it..I tried (setq templst (readit "grades.txt")) and BAM! EVERYTHING worked!
 
-My car doesn't start, I've checked everything, battery, spark plugs, wires, air filter...
-It has gas?
-...
 
Now I only have to use lisp to put back the dots in my grades...piece of cake, maybe =D
thank you thank you thank you thank you thank you (inhaaaaaale) thank you thank you

Lee Mac 发表于 2022-7-6 00:55:05

Glad you were able to solve it Jef! - well done
 
My earlier example using "c:\\grades.txt" as an example filepath was perhaps confusing. Since the function uses findfile, the filepath argument may be an absolute filepath (e.g. "c:\\grades.txt"), relative filepath (e.g. "..\\grades.txt") or just a filename (e.g. "grades.txt") for which the function will search the working directory and SFSP.
 
Nevertheless, I'm sure you've learnt a great deal from the experience!
 
Lee
页: 1 [2]
查看完整版本: opening file (strings) into li