|
-
Jul 20th, 2001, 04:03 PM
#1
Thread Starter
Lively Member
Checking if a file exists
Is there an efficient way of checking if a file exists? =)
If so please explain. I've always been poor in this area, and always done it the cheap and unefficient way. Hehehe
Thanks
-
Jul 20th, 2001, 04:06 PM
#2
VB Code:
If Len(Dir$("C:\myFile.txt")) > 0 Then
MsgBox "File Exists"
Else
MsgBox "File Not Found"
End If
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 20th, 2001, 04:10 PM
#3
PowerPoster
you could drop the Len() couldn't you? Dir() works just fine.
-
Jul 20th, 2001, 06:59 PM
#4
PowerPoster
Hi
You could also check for error numbers when opening a file using Err.Number ... this allows u to check for all file problems such as not existing, already open, no directory etc etc etc etc... look up Err.Number in help for all of the possible checks.
Regards
Stuart
-
Jul 20th, 2001, 09:15 PM
#5
Registered User
crptcblade is spot on, checking the length of returned value from dir is much faster than doing a string comparison and is therefore the optimised approach.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|