How to check if it is a directory or a file?
Is there way to do that by using IfFileExists? Thanks.
Archive: How to check if it is a directory or a file?
How to check if it is a directory or a file?
Is there way to do that by using IfFileExists? Thanks.
Use \*.* on the end to check a path is a directory rather than a file.
Stu
Originally posted by Afrow UKThat 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?
Use \*.* on the end to check a path is a directory rather than a file.
Stu
Swap the logic around then.
${If} ${FileExists} Path
${AndNot} ${FileExists} Path\*.*
# Is a file
${EndIf}
Stu
Originally posted by Afrow UKBut {AndNot} is a valid command...
Swap the logic around then.
${If} ${FileExists} Path
${AndNot} ${FileExists} Path\*.*
# Is a file
${EndIf}
Stu
Originally posted by JohnChenI meant {AndNot} is NOT a valid command.
But {AndNot} is a valid command...
I was hoping you would look it up :) AndIfNot.
Stu
Originally posted by Afrow UKSorry, I should have figured out. Thanks a lot.
I was hoping you would look it up :) AndIfNot.
Stu
...Man, now you made me remember back when LogicLib still used ${AndUnless}. :)
Hi 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.
That is to say whether the path is a file name or a directory, the results are the same only if it is really existed.
If you want to determine whether a path is directory or not, I think you must use PathIsDirectory Function.
System::Call `shlwapi::PathIsDirectory(t)i("C:\AnEmptyFolderName").R0`
${If} $R0 <> 0
MessageBox MB_OK Path `"C:\AnEmptyFolderName" is a directory!`
${EndIf}
Originally posted by jiakeErr... 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.)
Hi 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.
Yes, with your code if AnEmptyFolderName is a directory you get both message boxes. If it is a file, you only get one (the 2nd). (And yes I just tried it to be sure :)).
Stu