FileSystemWatcher: Fix for lowercase?

P

Paul

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
 
H

Herfried K. Wagner [MVP]

Paul said:
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.

That didn't work for me. 'Name'/'FullName' returned the same string that
was passed to the 'DirectoryInfo''s constructor (.NET 1.1 SP1, Windows XP
Professional SP2).
 
P

Paul

So there's no way of fixing the case? Suppose the next best thing is making
the start of each word a capital then. Pain!

Cheers,
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top