can somone please tell me how to cheack if a file exsits.
please make it as simple as possible becuase I'm still sleeping although its 2:10 in Rhode Island
Printable View
can somone please tell me how to cheack if a file exsits.
please make it as simple as possible becuase I'm still sleeping although its 2:10 in Rhode Island
Try this:
Code:Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
If fso.FileExists("c:\windows\desktop\myFile.txt")=True then
msgbox "I'm here"
Else
msgbox "File not present"
end if
this is better because it doesnt require the reference to the scripting host.Code:Function VBDoesFileExist(FilePath As String) As Boolean
On Error Resume Next
Dim strRet As String
' see if the file exists
strRet = Dir$(FilePath, vbNormal Or vbSystem Or vbHidden Or vbReadOnly)
' check to make sure the handle isnt invalid
If strRet <> "" Then
VBDoesFileExist = True
Else
VBDoesFileExist = fale
End If
' use:
' VBDoesFileExist(c:\windows\desktop\myilfe.txt)
End Function
whats the diffrence? to me one is longer, one is shorter.
Sorry, if I'm dont getting it right now becuase I am tried, the first one seems simple any easy for me.
You can use the Dir Function.
Code:RetVal = Dir("C:\MyFile")
If RetVal <> "" Then
MsgBox ("File Exsists")
Else
MsgBox ("File Does not exsist")
End If