How to monitor a folder for change in vb6.0

I am looking to be pointed in the right direction.
We need to monitor a folder on our server and when there is a new pdf file put into that folder we need to pull the file name as a string and compare that to another string.
I need to know how to have a dll monitor the folder and pull the file name out of the folder?

More info. The client will pass a string to the dll, the dll will watch the folder for 60 seconds, and if in 60 secods there is a change in the folder it will pull the name of the file put into the folder?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

See this example:

Creating a Watched Folder with FindChangeNotification
Here is an example which runs on a web-site some users are allowed to upload files. When a new file arrives the software detects the arrival an does something.

I found the examples on the internet a little bit unsuitable so I created an a version that just used a time control.

the example also uses a list box lstActions

The coe uses mlAction to decide what it is currently doing.

1) So first it sets a waiting for change which is the the form of a process which has a handle
It connects to the process via the handle
2) when a change notification arrives it closes the wating for a change handle and runs the process
then it sets the flag to tell the timer to restart the game

Option Explicit

Dim mlAction As Long

'Monitoring file changes
' borowed concepts from:
'A popular function developers are implementing these days consists of monitoring a system for changes to files. This feature can be used to detect situations where viruses modify your system files, or web sites add cookies and other files to your system. It can also be used to notify you that a shared file has been updated and the changes need to be reviewed.
'This article will discuss monitoring for file changes in Visual Basic 6.0 using the FindFirstChangeNotification API function. The parameters passed to the function describe the folder you want to monitor, whether to monitor the folder's subfolders, and the type of file changes to detect. You can also use the FindNextChangeNotification API function to continue monitoring the folder after you have detected a file change, and the FindCloseChangeNotification API function to stop monitoring the folder. The sample code below demonstrates monitoring the Windows folder for file changes.
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, _
    ByVal dwNotifyFilter As Long) As Long

Private Declare Function FindCloseChangeNotification Lib "kernel32" _
   (ByVal hChangeHandle As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" _
   (ByVal hChangeHandle As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
        (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Dim FOP As New zFOP
Dim GF As New zGF

Private Sub zProcessChange(psFolder As String)

' run all batch files in the folder

Dim Files
Dim vFile

' get the files in the folder
Set Files = FOP.GetFiles(psFolder + "\*.bat", True)
If Files Is Nothing Then Exit Sub
Dim OK

For Each vFile In Files
    ' process ach file
    zStatus "Found: " + vFile
    ' wait until complete
    OK = GF.RunCommandOK(psFolder + "\" + vFile, vbNormal)
    'now kill the file
    OK = GF.KillFileOK(psFolder + "\" + vFile)

End Sub

Public Sub zStatus(psStatus As String)

' Display Status

lstActions.AddItem Format(Now, "dd-mm-yy hh:nn:ss") + " " + psStatus, 0

If lstActions.ListCount > 100 Then
    lstActions.RemoveItem lstActions.ListCount - 1
End If

End Sub

Private Sub Form_Load()
mlAction = 0
timStartWaiting.Interval = 100
Dim sh, sw
If GF.Minimized(Me, sw, sh) Then Exit Sub
lstActions.Move 0, 0, sw, sh

End Sub

Private Sub Form_Unload(Cancel As Integer)
mlAction = 9
timStartWaiting.Interval = 0
End Sub

Private Sub lstActions_Click()

End Sub

Private Sub timStartWaiting_Timer()

Dim sFolder As String
sFolder = "C:\WINNT\System32\Logfiles\dns"

Static lWaitHandle As Long
Static lResult As Long

' Action = 0 means start waiting
If mlAction = 0 Then
    zStatus "Waiting"
    timStartWaiting.Interval = 0
    lWaitHandle = FindFirstChangeNotification(sFolder, _

   mlAction = 1
End If

' could have used this but chose not to
'r = FindNextChangeNotification(hWatched)

If mlAction = 1 Then

    lResult = WaitForSingleObject(lWaitHandle, 50)
    If lResult = 0 Then
        timStartWaiting.Interval = 0
        mlAction = 0
        zStatus "Change notified"
        FindCloseChangeNotification lWaitHandle
        ' DO THE THING
        zProcessChange sFolder
        'FindNextChangeNotification (hWatched)
        timStartWaiting.Interval = 100
        ' folder has changed
        timStartWaiting.Interval = 100
    End If
End If

If mlAction = 9 Then
    FindCloseChangeNotification lWaitHandle
    timStartWaiting.Interval = 0
    mlAction = 99
    zStatus "Closed"
End If

   'flag requests detection of file name changes including renaming, creating, or deleting a file name.
   'The FILE_NOTIFY_CHANGE_LAST_WRITE flag requests notification when a file'
   'is written to the disk. The FILE_NOTIFY_CHANGE_ATTRIBUTES flag requests notification when
   'a file's attributes have changed (such as resetting the file's ReadOnly attribute).
   'Other file change flags available for use include FILE_NOTIFY_CHANGE_DIR_NAME'
   'which detects folder name changes, FILE_NOTIFY_CHANGE_SIZE which detects changes
   'in the file's size (this is covered by the FILE_NOTIFY_CHANGE_LAST_WRITE flag),
   'and FILE_NOTIFY_CHANGE_SECURITY which detects changes to a file's security descriptor.
End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.