Link to home
Start Free TrialLog in
Avatar of JulianDavies
JulianDavies

asked on

Watching folders...

Is it possible (preferably without the use of timers) to "watch" a folder on the local hard-disk. i.e. somehow fire an event when a file is added to the folder?

Any help with this would be greatly appreciated.

Thanks!

Julian
Avatar of caraf_g
caraf_g

<ping>
don't think so but why don't you want to use timers?? then it's easy.....

Make a reference to microsoft scripting runtime.
Add a timer to your form

Private sc As New Scripting.FileSystemObject
Private lastModified As String

Private Sub dowhatever()
    MsgBox "changed"
End Sub

Private Sub CHFiles(ByVal path As String)
    Dim f As Scripting.Folder, tmp As String
    Set f = sc.GetFolder(path)
    tmp = f.DateLastAccessed
    If (tmp <> lastModified) Then
        lastModified = f.DateLastAccessed
        dowhatever
    End If
End Sub
   

Private Sub Timer1_Timer()
    Call CHFiles(App.path)
End Sub
Sorry, i thought it wrote "preferable with the user of timers" :-(...sorry about that then :-/

regards,
CJ
You can use Sleep API instead of Timer control.....

I don't think it is possible without checking the folder frequrntly after a small event of time. It'll be neccassary to check the folder changed on regular intervals of time.

Ajay chadha ... :-)
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See:

"Spy on a Folder to Detect When it Changes"
http://www.thescarms.com/vbasic/FolderSpy.htm
Avatar of JulianDavies

ASKER

That's exactly what I needed.  Thank you!