FileSystemWatcher returns changed files in lower case

  • Thread starter Thread starter Donald Xie
  • Start date Start date
D

Donald Xie

Hi,

The FileSystemWatcher works fine to return the files
changed. However, the path returned through
FileSystenArgs.FullName is always in lower cases, e.g.,
c:\projectfiles\watched\foo.txt even though both the
directory and file names are in proper case like
c:\ProjectFiles\Watched\Foo.txt.

I've tried to instantiate a DirectoryInfo or FileInfo
with the returned file path, hoping they will return the
path in proper case but without success. Is there a work
around? The project I'm working on copies the changes to
another machine so it's important that I can maintain the
case so users won't get confused.

Thanks in advance,
Donald Xie
 
Hi Jeffery,

Thanks for the reply. I've tried this, but it only returns proper cases for
the file name, not the directory it's in. I guess we can go all the way back
to the root directory, but this could be really slow. Not really the
solution for my project unfortunately.

The best solution would be to find a way to have the FileSystemWatcher to
return file path in proper case, but I haven't had any luck to achieve this.
Is there anything I can do? Perhaps I will have to try to PInvoke API
functions, but I was hoping that I didn't have to go into such trouble. Any
suggestions will be appreciated.

Cheers,
Donald Xie

Jeffrey Tan said:
Hi Donald,

I think because the constructor of FileInfo takes a path, it never feels
the need to retrieve the cased path.
One (not particularly pretty) way to get the correctly cased path from an
uncased path would be as follows:

static void Main(string[] args)
{
string fullyqualifiedfilename = @"G:\customer\phillips\tester.exe"; //
this works
FileInfo fiReq = new FileInfo(fullyqualifiedfilename);

DirectoryInfo di = new DirectoryInfo (fiReq.DirectoryName);
FileInfo[] fis = di.GetFiles();
foreach (FileInfo fi in fis)
{
if (String.Compare(fi.FullName,fullyqualifiedfilename,true) == 0)
{
string CorrectlyCasedFileName = fi.FullName;
Console.WriteLine("Found: " + CorrectlyCasedFileName);
}
}
Console.Read();
}

HTH.

Regards
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Donald Xie" <[email protected]>
| Sender: "Donald Xie" <[email protected]>
| Subject: FileSystemWatcher returns changed files in lower case
| Date: Mon, 11 Aug 2003 17:08:11 -0700
| Lines: 18
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNgZdE3jSnD+fJ9Q6qu0t9rx/hx7Q==
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:51055
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Hi,
|
| The FileSystemWatcher works fine to return the files
| changed. However, the path returned through
| FileSystenArgs.FullName is always in lower cases, e.g.,
| c:\projectfiles\watched\foo.txt even though both the
| directory and file names are in proper case like
| c:\ProjectFiles\Watched\Foo.txt.
|
| I've tried to instantiate a DirectoryInfo or FileInfo
| with the returned file path, hoping they will return the
| path in proper case but without success. Is there a work
| around? The project I'm working on copies the changes to
| another machine so it's important that I can maintain the
| case so users won't get confused.
|
| Thanks in advance,
| Donald Xie
|
 
Hi Donald,

I am glad to see your work aroud.
I think the "all lower case" issue is really a problem and take much
inconvinience to the customer.
I think you can put your suggestion to Microsoft at the link below:
http://register.microsoft.com/mswish/suggestion.asp?from=cu&fu=/isapi/go
mscom%2Easp%3Ftarget%3D%2Fmswish%2Fthanks%2Ehtm
We are glad you can provide good suggestion for our products.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Donald Xie" <[email protected]>
| Sender: "Donald Xie" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: FileSystemWatcher returns changed files in lower case
| Date: Thu, 14 Aug 2003 20:24:01 -0700
| Lines: 132
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcNi3Kw1sudZgWh9RA6zjteW+Z+Riw==
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:51343
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| For what it's worth, I extended Jeffery's suggestion to
| get the proper case names for all directory for the file:
|
| private void GetProperCase(ref string FilePath)
| {
| // Separate all directory names and the file name
| string[] dirs = FilePath.Split
| (Path.DirectorySeparatorChar);
|
| // Start from the drive root directory
| FilePath = FilePath.Substring(0, FilePath.IndexOf
| (Path.DirectorySeparatorChar, 0) + 1);
|
| // Enumerate from top down.
| for (int i = 0; i < dirs.Length - 1; ++i)
| {
| DirectoryInfo di = new DirectoryInfo(FilePath);
| FileSystemInfo[] infos = di.GetFileSystemInfos(dirs[i
| + 1]);
| if (infos.Length > 0)
| FilePath = infos[0].FullName;
| }
| }
|
| It actually works quite fast, so I'll settle on this for
| now. It appears that there's nothing I can do to get the
| FileSystemWatcher to return proper case names.
|
| I've also found that this "all lower case" approach is
| used by quite a lot of .NET class libraries, such as
| Assembly.GetLocation and
| AppDomain.CurrentDomain.FriendlyName. Guess that's the
| design decision taken by the .NET team...
|
| Cheers,
| Donald Xie
| >-----Original Message-----
| >
| >Hi Donald,
| >
| >I think because the constructor of FileInfo takes a
| path, it never feels
| >the need to retrieve the cased path.
| >One (not particularly pretty) way to get the correctly
| cased path from an
| >uncased path would be as follows:
| >
| >static void Main(string[] args)
| >{
| > string fullyqualifiedfilename =
| @"G:\customer\phillips\tester.exe"; //
| >this works
| > FileInfo fiReq = new FileInfo
| (fullyqualifiedfilename);
| >
| > DirectoryInfo di = new DirectoryInfo
| (fiReq.DirectoryName);
| > FileInfo[] fis = di.GetFiles();
| > foreach (FileInfo fi in fis)
| > {
| > if (String.Compare
| (fi.FullName,fullyqualifiedfilename,true) == 0)
| > {
| > string CorrectlyCasedFileName =
| fi.FullName;
| > Console.WriteLine("Found: " +
| CorrectlyCasedFileName);
| > }
| > }
| > Console.Read();
| >}
| >
| >HTH.
| >
| >Regards
| >Jeffrey Tan
| >Microsoft Online Partner Support
| >Get Secure! - www.microsoft.com/security
| >This posting is provided "as is" with no warranties and
| confers no rights.
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Donald Xie" <[email protected]>
| >| Sender: "Donald Xie" <[email protected]>
| >| Subject: FileSystemWatcher returns changed files in
| lower case
| >| Date: Mon, 11 Aug 2003 17:08:11 -0700
| >| Lines: 18
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V5.50.4910.0300
| >| Thread-Index: AcNgZdE3jSnD+fJ9Q6qu0t9rx/hx7Q==
| >| Newsgroups: microsoft.public.dotnet.framework
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework:51055
| >| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| >|
| >| Hi,
| >|
| >| The FileSystemWatcher works fine to return the files
| >| changed. However, the path returned through
| >| FileSystenArgs.FullName is always in lower cases,
| e.g.,
| >| c:\projectfiles\watched\foo.txt even though both the
| >| directory and file names are in proper case like
| >| c:\ProjectFiles\Watched\Foo.txt.
| >|
| >| I've tried to instantiate a DirectoryInfo or FileInfo
| >| with the returned file path, hoping they will return
| the
| >| path in proper case but without success. Is there a
| work
| >| around? The project I'm working on copies the changes
| to
| >| another machine so it's important that I can maintain
| the
| >| case so users won't get confused.
| >|
| >| Thanks in advance,
| >| Donald Xie
| >|
| >
| >.
| >
|
 
Back
Top