-
In another project i am working on, i want a user to be notified when there is a new file in a directory. How can i write something that scans a directory on a given interval and look for only new files? If possible, i want to pass the file name to the program so they can open the file if they choose to at my prompt.
Thanks,
Rob
-
I cannot guarantee that this will work, it was found in my half-done folder. If you encounter errors, reply. The function will return a variant containing an array.
Function SearchDIR(directory)
On Error Resume Next
Static dirname
Static oldfiles() As String
Static newfiles() As String
Static foundfiles() As String
ReDim newfiles(0) As String
fil = Dir(directory)
Do Until fil = ""
If fil <> "." And fil <> ".." Then
ReDim Preserve newfiles(UBound(newfiles) + 1)
newfiles(UBound(newfiles)) = fil
test = oldfiles(0)
If Err Then
For n = 0 To UBound(oldfiles)
If newfiles(UBound(newfiles)) = oldfiles(n) Then ReDim Preserve foundfiles(UBound(foundfiles) + 1): foundfiles(UBound(foundfiles)) = newfiles(UBound(newfiles)): Exit For
Next n
End If
End If
fil = Dir()
Loop
ReDim oldfiles(UBound(newfiles))
For Each n In newfiles
oldfiles(n) = newfiles(n)
Next n
SearchDIR = foundfiles()
End Function