473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

File.Exists case change

In our series of "probably something simple"...

I am doing a File.Exists operation to check if a file exists. Let's
assume that this file is C:/test.txt.

Now, if I do File.Exists("C:\\Test.txt"), I do not want it to tell me
that the file exists - this is a check for a File.Move operation (some
file renaming functionality). But if I check C:\\test.txt, it should
return true.

Any suggestions?
Nov 14 '08 #1
8 12157
DH
Sweetiecakes wrote:
In our series of "probably something simple"...

I am doing a File.Exists operation to check if a file exists. Let's
assume that this file is C:/test.txt.

Now, if I do File.Exists("C:\\Test.txt"), I do not want it to tell me
that the file exists - this is a check for a File.Move operation (some
file renaming functionality). But if I check C:\\test.txt, it should
return true.

Any suggestions?
Sweetiecakes,
the question does not make mush sense you are saying you dont want it to
tel you if the file esists but the it should return true;
File.Exists() returns a boolean (true or false) if the file exists it
returns true otherwise false.

if you want to check a folder to make sure a file with that name does
not exist you could do:
if(!File.Exists(destpath)){
//move
}
else{
//do whatever you want
}
Nov 14 '08 #2
DH wrote:
Sweetiecakes,
the question does not make mush sense you are saying you dont want it to
tel you if the file esists but the it should return true;
File.Exists() returns a boolean (true or false) if the file exists it
returns true otherwise false.

if you want to check a folder to make sure a file with that name does
not exist you could do:
if(!File.Exists(destpath)){
//move
}
else{
//do whatever you want
}
I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).

Thanks
Nov 14 '08 #3
I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).

Thanks
Nov 14 '08 #4
DH
Sweetiecakes wrote:
DH wrote:
>Sweetiecakes,
the question does not make mush sense you are saying you dont want it
to tel you if the file esists but the it should return true;
File.Exists() returns a boolean (true or false) if the file exists it
returns true otherwise false.

if you want to check a folder to make sure a file with that name does
not exist you could do:
if(!File.Exists(destpath)){
//move
}
else{
//do whatever you want
}

I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).

Thanks
That is not going to be possible in a windows environment. In windows
test.txt and Test.txt are the same thing. so unless ur using a *nix
environment in windows you will never have test.txt and Test.txt in the
same directory.
Nov 14 '08 #5
"Sweetiecakes" <x@x.comwrote in message
news:49***********************@news.fv.fi...
I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).
I would say you should try to create a FileInfo object and then (assuming
Exists returns true) test its Name property against your original string in
a case-sensitive manner. This is off the top of my head, and I can't be
positive that the FileInfo object will return the properly-cased file name
in the Name property or if it will simply parrot what you put in, but my gut
feeling is that you'll get the real file name. Try it.
Nov 14 '08 #6
DH
Sweetiecakes wrote:
I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).

Thanks
I guess if you really want to make it case sensitive you could use
Directory.GetFiles()
and go through the files and check them but this is going to be slow and
inefficient if the folder has a lot of files.
Nov 14 '08 #7
Sweetiecakes wrote:
I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).
I am very sure that trying to use NTFS as a case sensitive file system
will be a disaster.

But if you insist, then try:

public static class MyFile
{
public static bool MyExists(string fnm)
{
if(!File.Exists(fnm)) return false;
return
Array.Exists(Directory.GetFiles(Path.GetDirectoryN ame(fnm)), s =s ==
Path.GetFullPath(fnm));
}

}
Arne
Nov 15 '08 #8
MC

"Arne Vajhøj" <ar**@vajhoej.dkwrote in message news:49***********************@news.sunsite.dk...
Sweetiecakes wrote:
>I don't know what I've been typing in my last message - but basically,
what I meant, was that I want the File.Exists() command to be
_case-sensitive_, so that test.txt and Test.txt are not the same thing
(such as in an Unix environment).
I am very sure that trying to use NTFS as a case sensitive file system
will be a disaster.
Right -- to underscore that point -- Windows NTFS is *not* a case-sensitive file system and you will find discrepancies from one machine to another as to how case is handled. Under Windows, if test.txt exists, then so does Test.Txt, because they are the same file.
Nov 15 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Xah Lee | last post by:
is there a way to condense the following loop into one line? # -*- coding: utf-8 -*- # python import re, os.path imgPaths= # change the image path to the full sized image, if it exists
52
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the...
2
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
3
by: OdAwG | last post by:
Hello All, I would i check to see if a file exist and if it does exist, then rename the file with the date and time attached to the name: Example: If...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
2
by: CCLeasing | last post by:
If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" + comOffice.Text + @"\" + numTerm.Value.ToString())) { storereport(); } else { Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +...
5
by: B. Williams | last post by:
I need some assistance with random access file processing. I have a function that I would like to change from sequential file processing to random access. Thanks in advance. void...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.