By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

File Watcher returns LOWER CASE only.

P: n/a
I am using a file watcher to watch for files changing. My problem is: the
string file info returned is all LOWER CASE.

Below is the important part of the code?

Any suggestions?

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.IO;

using System.Runtime.InteropServices;

private void InitializeComponent()

{

this.fileSystemWatcher1 = new
System.IO.FileSystemWatcher();

((System.ComponentModel.ISupportInitialize)(this.f ileSystemWatcher1)).BeginInit();

//

// fileSystemWatcher1

//

this.fileSystemWatcher1.EnableRaisingEvents = true;

this.fileSystemWatcher1.IncludeSubdirectories = true;

this.fileSystemWatcher1.Path = "C:\\";

this.fileSystemWatcher1.Filter = "*.*";

this.fileSystemWatcher1.Deleted += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Deleted);

this.fileSystemWatcher1.Renamed += new
System.IO.RenamedEventHandler(this.fileSystemWatch er1_Renamed);

this.fileSystemWatcher1.Changed += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Changed);

this.fileSystemWatcher1.Created += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Created);

this.CanHandlePowerEvent = true;

this.CanPauseAndContinue = true;

this.CanShutdown = true;

this.ServiceName = "FileSysWatch";

((System.ComponentModel.ISupportInitialize)(this.f ileSystemWatcher1)).EndInit();

private void fileSystemWatcher1_Changed(object sender,
System.IO.FileSystemEventArgs e)

{

name = e.Name; //??LOWER CASE ONLY!!

}
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Your problem is that it returns only files which are lower case or makes all
file names lower case?
If it returns name in lower case, it's no problem, file names are not case
sensitive in Windows.

"jimdscudder" <ji*********@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am using a file watcher to watch for files changing. My problem is: the
string file info returned is all LOWER CASE.

Below is the important part of the code?

Any suggestions?

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.IO;

using System.Runtime.InteropServices;

private void InitializeComponent()

{

this.fileSystemWatcher1 = new
System.IO.FileSystemWatcher();

((System.ComponentModel.ISupportInitialize)(this.f ileSystemWatcher1)).BeginI
nit();
//

// fileSystemWatcher1

//

this.fileSystemWatcher1.EnableRaisingEvents = true;

this.fileSystemWatcher1.IncludeSubdirectories = true;

this.fileSystemWatcher1.Path = "C:\\";

this.fileSystemWatcher1.Filter = "*.*";

this.fileSystemWatcher1.Deleted += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Deleted);

this.fileSystemWatcher1.Renamed += new
System.IO.RenamedEventHandler(this.fileSystemWatch er1_Renamed);

this.fileSystemWatcher1.Changed += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Changed);

this.fileSystemWatcher1.Created += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Created);

this.CanHandlePowerEvent = true;

this.CanPauseAndContinue = true;

this.CanShutdown = true;

this.ServiceName = "FileSysWatch";

((System.ComponentModel.ISupportInitialize)(this.f ileSystemWatcher1)).EndIni
t();
private void fileSystemWatcher1_Changed(object sender,
System.IO.FileSystemEventArgs e)

{

name = e.Name; //??LOWER CASE ONLY!!

}

Nov 17 '05 #2

P: n/a
The problem is i use this to back up files and I world like the backed up
files and paths to reflect the case they were first in.

"Lebesgue" <no****@spam.jp> wrote in message
news:uk**************@TK2MSFTNGP10.phx.gbl...
Your problem is that it returns only files which are lower case or makes
all
file names lower case?
If it returns name in lower case, it's no problem, file names are not case
sensitive in Windows.

"jimdscudder" <ji*********@nospam.nospam> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am using a file watcher to watch for files changing. My problem is:
the
string file info returned is all LOWER CASE.

Below is the important part of the code?

Any suggestions?

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.IO;

using System.Runtime.InteropServices;

private void InitializeComponent()

{

this.fileSystemWatcher1 = new
System.IO.FileSystemWatcher();

((System.ComponentModel.ISupportInitialize)(this.f ileSystemWatcher1)).BeginI
nit();

//

// fileSystemWatcher1

//

this.fileSystemWatcher1.EnableRaisingEvents = true;

this.fileSystemWatcher1.IncludeSubdirectories = true;

this.fileSystemWatcher1.Path = "C:\\";

this.fileSystemWatcher1.Filter = "*.*";

this.fileSystemWatcher1.Deleted += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Deleted);

this.fileSystemWatcher1.Renamed += new
System.IO.RenamedEventHandler(this.fileSystemWatch er1_Renamed);

this.fileSystemWatcher1.Changed += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Changed);

this.fileSystemWatcher1.Created += new
System.IO.FileSystemEventHandler(this.fileSystemWa tcher1_Created);

this.CanHandlePowerEvent = true;

this.CanPauseAndContinue = true;

this.CanShutdown = true;

this.ServiceName = "FileSysWatch";

((System.ComponentModel.ISupportInitialize)(this.f ileSystemWatcher1)).EndIni
t();

private void fileSystemWatcher1_Changed(object sender,
System.IO.FileSystemEventArgs e)

{

name = e.Name; //??LOWER CASE ONLY!!

}


Nov 17 '05 #3

P: n/a
"jimdscudder" <ji*********@nospam.nospam> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
The problem is i use this to back up files and I world like the backed up
files and paths to reflect the case they were first in.


I believe that you can get the original case of the filename by creating a
File object using the filename passed in. Not sure, though. Try it.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Nov 17 '05 #4

P: n/a
I've been struggling with this too, but the solution is dead simple if
you're willing to reference a COM component from your .NET project.
Here are the steps:

1.) Add a reference to your project to the "Microsoft Scripting
Runtime" COM object
2.) Build the following function:

public string GetCaseSensitivePath(string path) {
Scripting.FileSystemObjectClass fso = new FileSystemObjectClass();
return fso.GetAbsolutePathName(path);
}
3.) Build a helper function to fix your FileSystemEventArgs object:

private FileSystemEventArgs FixFileSystemEventArgs(FileSystemEventArgs
e) {
string path = GetCaseSensitiveFilePath(e.FullPath);
return new FileSystemEventArgs(e.ChangeType,
Path.GetDirectoryName(path), Path.GetFileName(path));
}
This one took me forever to figure out. I even built my own path
parser, but I'll take a pre-built 2 liner from classic VBScript over
maintaining that parser any day, even if it does seem icky to reference
a COM component from C#.

- Matt McElheny

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.