IfFileExists returns a few results I wouldn't really expect:
Evaluate: "d:" - Return value: True (where "d:" is my secondary drive)
Evaluate: "c:" - Return value: False (where "c:" is my primary drive)
Evaluate: "c:\Temp" - Return value: True (where "c:\Temp" does exist, but it's a folder on my primary drive, not a file)
Evaluate: "c:\Temp\" - Return value: False
Neither of the above are files, and "c:", compared to "d:" is no consistent result. The same goes for "c:\temp" and c:\temp\"
Macro Scheduler: 10.019e
OS: WinXP SP2
"IfFileExists" returns true for folders
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
I think what is happening is:
C:\Temp
Temp exists in c:\ = true - valid path
C:\Temp\
Look for emptystring in C:\Temp - makes no sense = false
But can't explain why you're getting true for "d:". I get false for all my drives include my drive d:. Not sure why you're getting true for d:
You should use IfDirExists for folders.
Will try a few other tests.
C:\Temp
Temp exists in c:\ = true - valid path
C:\Temp\
Look for emptystring in C:\Temp - makes no sense = false
But can't explain why you're getting true for "d:". I get false for all my drives include my drive d:. Not sure why you're getting true for d:
You should use IfDirExists for folders.
Will try a few other tests.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thank for the feedback, mtettmarmtettmar wrote: You should use IfDirExists for folders.
My point exactly... In this case I have an input box for the user, where he has to select a file. When a valid file is input, stuff happens.
Now, when the user chooses to type in his path, soon as he types for example 'c:\temp" even when he has in mind to type more, the path get's validated.
The point I'm trying to get across is that I expect (maybe wrongly) that IfFileExists should only return 'true' for files, not for folders as well, cause indeed if I wanted to check for a folder, I'd use the IfDirExists as you suggested.
Am I overlooking something when I expect the above? If it's intended that IfFileExists validates files and folders, then why have a function for folders only and not a function for files only?
A suggestion might be to have:
IfDirExists: dirs only
IfPathExists: dirs and files
IfFileExists: files only
Currently I experience a bit of confusion when I read the name "IfFileExists", read in the manual "If filename exists the first statements are executed" and then notice it also works for folders. "IfPathExists" would be a more consistent name with what it really does, imho.
A Function that only checks for the existence of an actual file, excluding folder, would be very nice to have.
Let me know if I'm overlooking something.