FileWatcher and File case

  • Thread starter Thread starter John
  • Start date Start date
J

John

Why does the System.IO.FileSystemEventArgs (in FileSystemWatcher object)
return lower case for the file? i.e. e.FullName will return
"c:\testingfilename.xml" instead of the origiiinal "c:\TestingFileName.xml".
Do I have the option to get the original case back? Thanks,
 
What difference doe it make? Windows file names are not case sensitive, you
can't have two files with the same name in the same base path, distinction
is not attained by case.
c:\File1.xml
C:\file1.xml --> same file
 
You don't answer my question. Is it possible or not? End users don't like to
see the file case changes when I copy the changed files to another
directories.
 
John,
e.FullPath should return the name of the file, it shouldn't force case
change (non-substantiated assessment) . I tested this on my computer, and,
sure enough the original case remained. Are you sure you are not changing
the case somewhere in your method? You can always use a FileInfo object and
use it's FullName property to get the original file name (assuming you're
handling change, rename, created events).

' Assumes Imports System.IO

Dim fseaPath, fiPath As String
Dim f As New FileInfo(e.FullPath)
fseaPath = e.FullPath
fiPath = f.FullName
MessageBox.Show("FileSystemEventArgs Path: " & fseaPath & ControlChars.CrLf
& "FileInfo Path: " & fiPath)
' The results I received were exactly the same, original file name,
unchanged case
 
Thanks for your help. I'll try again tonight and let you know. So far I only
get the lower case back (never change the file case anywhere in my
project!). I'l' try to use FileInfo object tonight. Thanks again.

John
 
You don't answer my question. Is it possible or not?

Right out of my own program...

'Save the real filename for later use
m_sFilename = New IO.FileInfo(filename).FullName

I need to display files using their proper filenames. It is too hard to read
file names that are all lowercase such as "incsubmitvolunteer.asp".

Actually it is, otherwise it wouldn't save the case, just like FAT16. IIRC,
you can have two files that differ only in case when using POSIX support,
but its dangerous.
 
I have a workaround soultion, but it's not very efficient.

protected void fileSystemWatcher_Renamed(object sender,
System.IO.RenamedEventArgs e)
{
string[] allFiles =
Directory.GetFiles(Path.GetDirectoryName(e.FullPath));
string newFullPath = e.FullPath;

foreach(string file in allFiles)
{
if(string.Compare(file, e.FullPath, true) == 0)
{
newFullPath = file;
break;
}
}

// newFullPath will have the correct name now
Debug.WriteLine("Renamed file: " + newFullPath);

}
 
I have a workaround soultion, but it's not very efficient.

protected void fileSystemWatcher_Renamed(object sender,
System.IO.RenamedEventArgs e)
{
string[] allFiles =
Directory.GetFiles(Path.GetDirectoryName(e.FullPath));
string newFullPath = e.FullPath;

foreach(string file in allFiles)
{
if(string.Compare(file, e.FullPath, true) == 0)
{
newFullPath = file;
break;
}
}

// newFullPath will have the correct name now
Debug.WriteLine("Renamed file: " + newFullPath);

}
 
Back
Top