monk Posted April 24, 2012 Posted April 24, 2012 I want to change this: ((member CNAME '( "W7072" )) (alert "WELL DONE!")) So that instead of listing "W7072" "W1234" etc etc I can have it "scan" through a text file and say yes CNAME is part of the text file or CNAME is not. Any pointers? Quote
monk Posted April 24, 2012 Author Posted April 24, 2012 I think what I am after is; All lines in the text file to be stored as a list within the routine. on which I can run "member". Not sure how to achieve the storing lines as a variable? Quote
pBe Posted April 24, 2012 Posted April 24, 2012 use SET function (setq val 0.0) (foreach var '("v1" "v2" "V3") (set (read var) (setq val (1+ val )))) Quote
monk Posted April 24, 2012 Author Posted April 24, 2012 Not sure that help pBe sorry. Or I dont understand! Lets say I have this.txt within this file is: W111 W123 W112 etc etc. I want to do: (setq THISLIST (strcat ((open "this.txt") foreach read-line))) Dont laugh at the code above but basically want THISLIST to return "W111" "W123" "W112" Quote
Stefan BMR Posted April 24, 2012 Posted April 24, 2012 (setq open_file (open "this.txt" "r")) (while (setq line (read-line open_file)) (setq THISLIST (cons line THISLIST)) ) Quote
Lee Mac Posted April 24, 2012 Posted April 24, 2012 Consider a function such as: (defun MemberOfTextFile ( item file / line ) (if (and (setq file (findfile file)) (setq file (open file "r")) ) (progn (while (and (setq line (read-line file)) (not (eq line item)))) (close file) (eq line item) ) ) ) Will return T if 'item' is equal to a line in the supplied Text File: (MemberOfTextFile "W111" "C:\\YourFolder\\Yourfile.txt") Otherwise, will return nil if either the file is not found or cannot be opened, or the item is not present. Note that the above is case-sensitive. Quote
monk Posted April 24, 2012 Author Posted April 24, 2012 Thanks everyone. Lee: How far wrong am I? Sorry im snowed under and trying to do ten things at once! (cond ((MemberOfTextFile "CNAME" "this.txt") (alert "WELL DONE!")) (t (princ "\nYou suck")) ) Quote
Lee Mac Posted April 24, 2012 Posted April 24, 2012 Lee: How far wrong am I? Sorry im snowed under and trying to do ten things at once! (cond ((MemberOfTextFile "CNAME" "this.txt") (alert "WELL DONE!")) (t (princ "\nYou suck")) ) Is 'CNAME' a variable or a string? Is "this.txt" in the Support Path or Working Directory? From your previous posts, I would guess you need to use: (if (MemberOfTextFile CNAME "this.txt") (alert "WELL DONE!") (princ "\nYou Suck") ) Quote
monk Posted April 24, 2012 Author Posted April 24, 2012 (edited) (setq CNAME (strcase (GETENV "COMPUTERNAME"))) Thats CNAME Thanks Edited April 24, 2012 by SLW210 Code Tags Added Quote
monk Posted April 24, 2012 Author Posted April 24, 2012 Works like a charm... I did look at IF statement... Obviously I glazed over! Quote
Lee Mac Posted April 24, 2012 Posted April 24, 2012 Works like a charm... I did look at IF statement... Obviously I glazed over! Note that COND would work equally well, but I felt IF was better suited for this case. (cond ( (MemberOfTextFile CNAME "this.txt") (alert "WELL DONE!") ) ( t (princ "\nYou Suck") ) ) Quote
pBe Posted April 25, 2012 Posted April 25, 2012 Not sure that help pBe sorry. Or I dont understand! Apologies Monk, I was refering to this one. Not sure how to achieve the storing lines as a variable? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.