![]() |
#1 |
Member
Join Date: Mar 2011
Posts: 80
|
How to check if it is a directory or a file?
Is there way to do that by using IfFileExists? Thanks.
|
![]() |
![]() |
![]() |
#2 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Use \*.* on the end to check a path is a directory rather than a file.
Stu |
![]() |
![]() |
![]() |
#3 |
Member
Join Date: Mar 2011
Posts: 80
|
|
![]() |
![]() |
![]() |
#4 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Swap the logic around then.
${If} ${FileExists} Path ${AndNot} ${FileExists} Path\*.* # Is a file ${EndIf} Stu |
![]() |
![]() |
![]() |
#5 |
Member
Join Date: Mar 2011
Posts: 80
|
|
![]() |
![]() |
![]() |
#6 |
Member
Join Date: Mar 2011
Posts: 80
|
|
![]() |
![]() |
![]() |
#7 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
I was hoping you would look it up
![]() Stu |
![]() |
![]() |
![]() |
#8 |
Member
Join Date: Mar 2011
Posts: 80
|
|
![]() |
![]() |
![]() |
#9 |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
...Man, now you made me remember back when LogicLib still used ${AndUnless}.
![]() |
![]() |
![]() |
![]() |
#10 |
Senior Member
Join Date: Oct 2007
Location: Shanghai, China
Posts: 207
|
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} Contact me: 137729898@qq.com |
![]() |
![]() |
![]() |
#11 | |
Major Dude
Join Date: Oct 2006
Posts: 1,892
|
Quote:
There's really no need to call PathIsDirectory or anything like that. |
|
![]() |
![]() |
![]() |
#12 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
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 |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|