How to check if it is a directory or a file?
Is there way to do that by using IfFileExists? Thanks.
12 posts
That is a clever idea. But how to check a file rather than a directory? Obviously we can't use $IfFileExists File, because here File could be either a file or a directory. Am I right?Originally Posted by Afrow UK View PostUse \*.* on the end to check a path is a directory rather than a file.
Stu
But {AndNot} is a valid command...Originally Posted by Afrow UK View PostSwap the logic around then.
${If} ${FileExists} Path
${AndNot} ${FileExists} Path\*.*
# Is a file
${EndIf}
Stu
I meant {AndNot} is NOT a valid command.Originally Posted by JohnChen View PostBut {AndNot} is a valid command...
Sorry, I should have figured out. Thanks a lot.Originally Posted by Afrow UK View PostI was hoping you would look it up 🙂 AndIfNot.
Stu
Err... Yes, and that's exactly what should happen. The directory exists, so both Ifs return true. If a file is NOT a directory, THEN only one of the two ifs will be true. That's how you distinguish files from directories. (As Stu has already explained, in his post.)Originally Posted by jiake View PostHi all, I have tested these two lines long ago :
IfFileExists "C:\AnEmptyFolderName\*.*" 0 +2
MessageBox MB_OK "C:\AnEmptyFolderName is a directory!"
IfFileExists "C:\AnEmptyFolderName" 0 +2
MessageBox MB_OK "C:\AnEmptyFolderName is a directory!"
I get the same result. It will show you two same message boxes.