Wait till file exist

momoko

Registered User.
Local time
Today, 06:41
Joined
Oct 7, 2001
Messages
41
Hi,
I help to do the following:

I need to monitor for a file in G:\test.pdf. If the file is there then copy if to C:\test.pdf. If the file is not there is will wait till it is there then copy to C:\. How can this be done?
Thanks.
 
You can code it using the FilesSystemObeject

something like this

Dim FileName
Dim objFSO
Dim objFolder
Dim objFile

folder = "c:\"
file = "fileName"

Loop

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folder)

For Each objFile In objFolder.File
If objFile.Name = file Then
...code
fileMoved = "True"
end if
next

Until fileMoved = "True"

This will probably create a loop that will eat up your cpu until the file appears.

So you'll need to use some sort of timer to pause it and check at intervals.

Hope this gets you started at least
 
One option is to create a form and use the On_Timer event to execute the following procedure.
Set the timer Interval to about 15000

Dim dbs As DAO.Database
On Error GoTo errproc

DoCmd.SetWarnings False
Set dbs = CurrentDb

With Application.FileSearch
.NewSearch
.LookIn = "G:\"
.SearchSubFolders = False
.FileName = "Test.pdf"
If .Execute() > 0 Then
FileSystemObject.CopyFile "G:\Test.pdf", "C:\"
End If
End With


Endproc:

Exit Sub

errproc:
MsgBox Err.Description
Resume Endproc


End Sub

I havn't tested this though!!
 

Users who are viewing this thread

Back
Top Bottom