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
Printable View
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
You can call the above function like this:VB Code:
Public Function FileExists(ByVal sFileName As String) As Boolean FileExists = (Len(Dir$(sFileName, vbHidden Or vbSystem Or vbReadOnly)) > 0) End FunctionVB Code:
If FileExists("c:\theFile.txt") = False Then MsgBox "The file does not exist!", vbInformation End If
Code:if dir("c:\filename.txt") <> "" then
'file exist
else
'File Does Not Exist
end if
Or You can Use the file system object
end ifVB Code:
Dim fso as new file system object if fso.fileexist("filname with Path")=true then msgbox "file exist" else msgbox "file not exist"
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