473,811 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Watcher returns LOWER CASE only.

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.Collecti ons;

using System.Componen tModel;

using System.Data;

using System.Diagnost ics;

using System.ServiceP rocess;

using System.IO;

using System.Runtime. InteropServices ;

private void InitializeCompo nent()

{

this.fileSystem Watcher1 = new
System.IO.FileS ystemWatcher();

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcher1)).Begin Init();

//

// fileSystemWatch er1

//

this.fileSystem Watcher1.Enable RaisingEvents = true;

this.fileSystem Watcher1.Includ eSubdirectories = true;

this.fileSystem Watcher1.Path = "C:\\";

this.fileSystem Watcher1.Filter = "*.*";

this.fileSystem Watcher1.Delete d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Del eted);

this.fileSystem Watcher1.Rename d += new
System.IO.Renam edEventHandler( this.fileSystem Watcher1_Rename d);

this.fileSystem Watcher1.Change d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Cha nged);

this.fileSystem Watcher1.Create d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Cre ated);

this.CanHandleP owerEvent = true;

this.CanPauseAn dContinue = true;

this.CanShutdow n = true;

this.ServiceNam e = "FileSysWat ch";

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcher1)).EndIn it();

private void fileSystemWatch er1_Changed(obj ect sender,
System.IO.FileS ystemEventArgs e)

{

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

}
Nov 17 '05 #1
4 2029
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.

"jimdscudde r" <ji*********@no spam.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.Collecti ons;

using System.Componen tModel;

using System.Data;

using System.Diagnost ics;

using System.ServiceP rocess;

using System.IO;

using System.Runtime. InteropServices ;

private void InitializeCompo nent()

{

this.fileSystem Watcher1 = new
System.IO.FileS ystemWatcher();

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcher1)).Begin I
nit();
//

// fileSystemWatch er1

//

this.fileSystem Watcher1.Enable RaisingEvents = true;

this.fileSystem Watcher1.Includ eSubdirectories = true;

this.fileSystem Watcher1.Path = "C:\\";

this.fileSystem Watcher1.Filter = "*.*";

this.fileSystem Watcher1.Delete d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Del eted);

this.fileSystem Watcher1.Rename d += new
System.IO.Renam edEventHandler( this.fileSystem Watcher1_Rename d);

this.fileSystem Watcher1.Change d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Cha nged);

this.fileSystem Watcher1.Create d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Cre ated);

this.CanHandleP owerEvent = true;

this.CanPauseAn dContinue = true;

this.CanShutdow n = true;

this.ServiceNam e = "FileSysWat ch";

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcher1)).EndIn i
t();
private void fileSystemWatch er1_Changed(obj ect sender,
System.IO.FileS ystemEventArgs e)

{

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

}

Nov 17 '05 #2
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******** ******@TK2MSFTN GP10.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.

"jimdscudde r" <ji*********@no spam.nospam> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.Collecti ons;

using System.Componen tModel;

using System.Data;

using System.Diagnost ics;

using System.ServiceP rocess;

using System.IO;

using System.Runtime. InteropServices ;

private void InitializeCompo nent()

{

this.fileSystem Watcher1 = new
System.IO.FileS ystemWatcher();

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcher1)).Begin I
nit();

//

// fileSystemWatch er1

//

this.fileSystem Watcher1.Enable RaisingEvents = true;

this.fileSystem Watcher1.Includ eSubdirectories = true;

this.fileSystem Watcher1.Path = "C:\\";

this.fileSystem Watcher1.Filter = "*.*";

this.fileSystem Watcher1.Delete d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Del eted);

this.fileSystem Watcher1.Rename d += new
System.IO.Renam edEventHandler( this.fileSystem Watcher1_Rename d);

this.fileSystem Watcher1.Change d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Cha nged);

this.fileSystem Watcher1.Create d += new
System.IO.FileS ystemEventHandl er(this.fileSys temWatcher1_Cre ated);

this.CanHandleP owerEvent = true;

this.CanPauseAn dContinue = true;

this.CanShutdow n = true;

this.ServiceNam e = "FileSysWat ch";

((System.Compon entModel.ISuppo rtInitialize)(t his.fileSystemW atcher1)).EndIn i
t();

private void fileSystemWatch er1_Changed(obj ect sender,
System.IO.FileS ystemEventArgs e)

{

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

}


Nov 17 '05 #3
"jimdscudde r" <ji*********@no spam.nospam> wrote in message
news:uo******** ******@tk2msftn gp13.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
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 GetCaseSensitiv ePath(string path) {
Scripting.FileS ystemObjectClas s fso = new FileSystemObjec tClass();
return fso.GetAbsolute PathName(path);
}
3.) Build a helper function to fix your FileSystemEvent Args object:

private FileSystemEvent Args FixFileSystemEv entArgs(FileSys temEventArgs
e) {
string path = GetCaseSensitiv eFilePath(e.Ful lPath);
return new FileSystemEvent Args(e.ChangeTy pe,
Path.GetDirecto ryName(path), Path.GetFileNam e(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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
10
15893
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
9
3263
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
6
1697
by: Andy B | last post by:
What would i use to look for changes in a file every minute?
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10652
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10395
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9211
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5700
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4346
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.