Jump to content

Recommended Posts

Posted

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")
    )
  )
  (...)
  (...)
)

 

Posted

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 

 

  • Like 1
  • Agree 1
Posted
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.

Posted

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"

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...