"IfFileExists" returns true for folders

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
durexlw
Newbie
Posts: 18
Joined: Mon Mar 17, 2008 1:19 pm

"IfFileExists" returns true for folders

Post by durexlw » Wed Apr 02, 2008 12:56 pm

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Apr 02, 2008 1:06 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

durexlw
Newbie
Posts: 18
Joined: Mon Mar 17, 2008 1:19 pm

Post by durexlw » Wed Apr 02, 2008 1:32 pm

mtettmar wrote: You should use IfDirExists for folders.
Thank for the feedback, mtettmar

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.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts