nitro322 Posted January 16, 2006 Share Posted January 16, 2006 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. http://www.legroom.net/ Link to comment Share on other sites More sharing options...
Valuater Posted January 16, 2006 Share Posted January 16, 2006 there are lots of ways... heres one idea $File = "the name give by the user ; check if folder exists DirGetSize($File) If @error= 1 Then ; the folder does not exist EndIf 8) Link to comment Share on other sites More sharing options...
MHz Posted January 16, 2006 Share Posted January 16, 2006 FileGetAttrib() correctly recognizes a directory. $attrib = FileGetAttrib(@WindowsDir) If not @error Then If StringInStr($attrib, "D") Then MsgBox(4096,"", "Source is a Directory.") EndIf Link to comment Share on other sites More sharing options...
nitro322 Posted January 16, 2006 Author Share Posted January 16, 2006 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. http://www.legroom.net/ Link to comment Share on other sites More sharing options...
MHz Posted January 16, 2006 Share Posted January 16, 2006 Thanks for the help.No problem. Thankyou for the nice gesture. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now