|
-
Apr 8th, 2001, 11:47 PM
#1
Thread Starter
Hyperactive Member
ok, befor I open a file, I want to make sure the path, and the file exist. How do I do that?
-
Apr 8th, 2001, 11:48 PM
#2
PowerPoster
Code:
if len(Dir$(path)) <> 0 Then "File Exists"
-
Apr 8th, 2001, 11:49 PM
#3
Fanatic Member
Try:
if len(dir$(path))=0 then 'file doesn't exist
-
Apr 8th, 2001, 11:49 PM
#4
PowerPoster
That was weird, almost the exact same syntax...
-
Apr 9th, 2001, 12:36 AM
#5
Fanatic Member
Yup, this has got to be one of the most common questions hey Lethal?
-
Apr 9th, 2001, 12:38 AM
#6
PowerPoster
yeah, it's in the top ten..
-
Apr 9th, 2001, 12:46 AM
#7
Addicted Member
You just have to be a bit careful as the Dir function will give you an error if you try and access an invalid drive or drive without a disk (eg A Drive)
For example:
Dir("A:\test.txt") will give an error if there is no disk in the A drive. The following function takes care of this.
Code:
Public Function FileExists(FileName As String) As Boolean
On Error GoTo FileNotFound
If Len(Dir$(FileName)) <> 0 Then
FileExists = True
Else
FileExists = False
End If
Exit Function
FileNotFound:
FileExists = False
End Function
Most of the time, this a complete waste of energy but this has pissed me off in the past. 
Hope this helps,
Nathan Liebke
-
Apr 9th, 2001, 12:50 AM
#8
PowerPoster
Or simply use the On Error Resume Next or another inline error handler routine. I was presumming he was going to do some validation before porting it to "Live Data".
-
Apr 9th, 2001, 01:04 AM
#9
Addicted Member
Yep, that would work too.
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
|