Jump to content

Recommended Posts

Posted

Gentlemen, I have yet another one of those odd problems that only seem to affect me. :-)

I'm writing a program that allows users to pass filenames to it. However, I need to verify that it 1) exists, and 2) is actually a file and not a directory. FileExists() will take care of condition 1), but I haven't been able to figure out how to handle condition 2). Any suggestions?

Thanks.

Oh, I just thought of a possible useful feature. How about modifying FileExists() to return 0 if the passed filename does not exists, 1 if it does and it's a file, or 2 if it does and it's a directory? This would offer a very simple solution for anyone that needs to distinguise between the two. Also, since either 1 or 2 will both be considered TRUE, it shouldn't have any unintentional side-effects (unless someone hard-coded the 1).

Of course, that doesn't help me here. :-) So, any suggestions? Again, thanks.

Posted

FileGetAttrib() correctly recognizes a directory.

$attrib = FileGetAttrib(@WindowsDir)
If not @error Then
    If StringInStr($attrib, "D") Then MsgBox(4096,"", "Source is a Directory.")
EndIf
Posted

MHz, FileGetAttrib() will work perfectly. I actually looked into it earlier, but somehow managed to miss the Directory attribute. Naturally.

Valuater, I hadn't thought about that approach. Will keep it in mind for the future.

Thanks for the help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...