Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Verify File

Status
Not open for further replies.

razchip

Technical User
Feb 2, 2001
133
US
I have been requested to start verifying whether a trigger file exits or not. If the file exist, I can go ahead and import the data, if the file is missing, I have to wait.

I would like some help in determining how I can check to see if this file exist, and if not, cancel the procedure. Thanks.

Thanks for the help.
Greg
 
Look into the Scripting FileSystemObject. You would need to add a reference to the scripting runtime library. You could also use the Dir function.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Try the following. I use this method quite often in work projects (can be placed in button action or any other sub):

Code:
Dim pathToFile As String
Dim fileAvail As Variant

'Open check file
'Change to local or network location
pathToFile = "c:\file.txt"
On Error Resume Next
fileAvail = FileLen(networkPath)

If fileAvail = 0 Then
    MsgBox "File not Available"
    'File Not available, do nothing
Else
    MsgBox "File Available!"
    'Insert procedure here
End If

Note: test file must contain at least one character. File can be any type (xls, doc, txt, etc)
 
Correction:

Code:
Dim pathToFile As String
Dim fileAvail As Variant

'Open check file
pathToFile = "c:\file.txt"
On Error Resume Next
fileAvail = FileLen(pathToFile)

If fileAvail = 0 Then
    MsgBox "File not Available"
    'File Not available, do nothing
Else
    MsgBox "File Available!"
    'Insert procedure here
End If

I pulled this from a live project and neglected to change an important element. Please disregard my first post...
 
If Dir$(strFilePath)<>"" Then
'It exists
else
'It don't. :)
End If

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top