Manuel_Kunde Posted September 16, 2021 Posted September 16, 2021 Hi all, how do I build an if-function where at least one of two conditions must be met? So if one of these .txt files or both are found. Thanks in advance. (if (or (findfile (strcat "\\path\\" "one.txt") (strcat "\\path\\" "two.txt") ) ) (...) (...) ) Quote
Grrr Posted September 16, 2021 Posted September 16, 2021 You were close, just needed to use findfile for each path: (if (or (findfile (strcat "\\path\\" "one.txt")) (findfile (strcat "\\path\\" "two.txt")) ) ; one of the files was found .. do stuff ) Or if you need to determine if both files were found, you can use cond : (setq file1 (findfile (strcat "\\path\\" "one.txt"))) (setq file2 (findfile (strcat "\\path\\" "two.txt"))) (cond ( (and file1 file2) (princ "found both files") ; do stuff... ) ( file1 (princ "found file1") ; do stuff... ) ( file2 (princ "found file2") ; do stuff... ) (t (princ "no files were found") ; do stuff... ) ); cond 1 1 Quote
Manuel_Kunde Posted September 16, 2021 Author Posted September 16, 2021 20 minutes ago, Grrr said: You were close, just needed to use findfile for each path: Or if you need to determine if both files were found, you can use cond : Thanks for the quick reply! The bad boy works now. Quote
mhupp Posted September 16, 2021 Posted September 16, 2021 100% @Grrr if you want more detail you could also do. (cond ((and file1 file2) (princ "\nFound both files:") (princ (strcat "\n" file1)) (princ (strcat "\n" file2)) ; do stuff... ) (file1 (princ (strcat "\nFound: " file1)) ; do stuff... ) (file2 (princ (strcat "\nFound: " file2)) ; do stuff... ) (t (princ "\nNo files were found") ; do stuff... ) ) ; cond "found both files" "C:\project1\text\one.txt" "C:\project1\text\two.txt" or "Found: C:\project1\text\one.txt" instead of "found both files" or "found file1" 1 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.