I'd like to check whether a file exist cos I want to Kill it and then call a function to write a file with the same path and name. My function cannot overwrite the file.
Printable View
I'd like to check whether a file exist cos I want to Kill it and then call a function to write a file with the same path and name. My function cannot overwrite the file.
VB Code:
If Len(Dir$("C:\myFile.txt")) > 0 Then MsgBox "File Exists!" Else MsgBox "File Doesn't Exist!" End If
By the by, why can't you overwrite the file?
VB Code:
Open "file.txt" For Output As #1 ...
that destroys the existing data in the file and replaces it with the new data...
You could also do
On Error Resume Next
Kill "C:\myFile.txt"
' Turn normal error checking back on
On Error Goto 0
' Now create the file
Create a file system object and use it's exist function for checking file exist or not. It is 10 times faster then dir .
For further contact [email protected]