|
-
Aug 3rd, 2006, 04:27 PM
#1
Thread Starter
New Member
[RESOLVED] How to check whether a file exists
What code would you use to get the program to report if a text file exists? Like if you want to write or overwrite a text file, but you want the program to say if the file doesn't yet exist, how would you do that?
Thanks
kitty500cat
Last edited by Hack; Aug 4th, 2006 at 06:28 AM.
Reason: Added [RESOLVED] to thread title and green "resolved" checkmark
I like cats; they taste like chicken.
-
Aug 3rd, 2006, 04:31 PM
#2
Re: How to check whether a file exists
VB Code:
Public Function FileExists(ByVal sFileName As String) As Boolean
FileExists = (Len(Dir$(sFileName, vbHidden Or vbSystem Or vbReadOnly)) > 0)
End Function
You can call the above function like this:
VB Code:
If FileExists("c:\theFile.txt") = False Then
MsgBox "The file does not exist!", vbInformation
End If
-
Aug 3rd, 2006, 10:01 PM
#3
Junior Member
Re: How to check whether a file exists
Code:
if dir("c:\filename.txt") <> "" then
'file exist
else
'File Does Not Exist
end if
-
Aug 3rd, 2006, 10:23 PM
#4
Re: How to check whether a file exists
Or You can Use the file system object
VB Code:
Dim fso as new file system object
if fso.fileexist("filname with Path")=true then
msgbox "file exist"
else
msgbox "file not exist"
end if
-
Aug 4th, 2006, 06:26 AM
#5
Thread Starter
New Member
Re: How to check whether a file exists
Thanks guys, I have known some basic stuff about VB6 for maybe 2 years, but I don't know terribly much yet; I just started getting into it again. I didn't know how to use the Dir function or whatever it's called, but this stuff answers my questions.
thanks again
kitty500cat
I like cats; they taste like chicken.
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
|