Hi,
As most people who use the FileSystemWatcher know, it returns lowercase text
for some strange reason. I know there's a workaround for the lowercase the
FileSystemWatcher returns by by passing the 'FullPath' property into the
constructor of a DirectoryInfo Class and reading the 'Name' property but I'm
not sure how or where I'd fit that into my code.
Could someone point me in the right direction?
Cheers,
Paul
Code follows..........
Private Sub LogChange(ByVal source As Object, ByVal e As
FileSystemEventArgs)
Dim strDestDir As String = "D:\"
Dim strString As String
Select Case e.ChangeType
Case IO.WatcherChangeTypes.Created
Try
If File.Exists(strDestDir & e.Name) = True Then
'File already exists in dest dir, wait for new file to
become available/not locked then delete it
Do Until FileIsReady(e.FullPath) = True
Loop
File.Delete(e.FullPath)
Exit Sub
Else
'File doesn't exist, wait for new file to become
available then move it.
Do Until FileIsReady(e.FullPath) = True
Loop
'Call popup form passing full path (lowercase for some
reason)
Popup(e.FullPath)
File.Move(e.FullPath, strDestDir & e.Name)
End If
Catch indexProblem As IndexOutOfRangeException
MsgBox("Error - No filename supplied")
Catch ioProblem As System.IO.IOException
'IOException error other than 'File already exists' (which
is checked above.)
MsgBox("Error - Can't process file named: " & e.FullPath)
End Try
End Select
End Sub
Function FileIsReady(ByVal sFileName As String) As Boolean
'Returns False if file is already opened by another process and the
'specified type of access is not allowed, the Open operation fails.
Dim nFileNum As Integer
nFileNum = FreeFile()
Try
FileOpen(nFileNum, sFileName, OpenMode.Binary, OpenAccess.Write)
FileClose(nFileNum)
Return True
Catch
Return False
End Try
End Function