473,756 Members | 3,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File.Exists(fil ePath) always returns false in release mode if filePath contains a white space

Hi All,

I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?

Thanks!

Feb 12 '07 #1
12 4563
Try this:

Dim strPath As String =
Environment.Get FolderPath(Envi ronment.Special Folder.Personal ).ToString
Dim strFile As String = IO.Path.Combine (strPath, "Test.txt")
MessageBox.Show (IO.File.Exists (strFile).ToStr ing)

--
Newbie Coder
(It's just a name)
Feb 12 '07 #2
I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version are
you targeting?

LS

"snow" <ba**********@y ahoo.comwrote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .
Hi All,

I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?

Thanks!
Feb 12 '07 #3
On Feb 12, 1:01 pm, "Lloyd Sheen" <a...@b.cwrot e:
I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version are
you targeting?

LS

"snow" <barbara_d...@y ahoo.comwrote in message

news:11******** **************@ m58g2000cwm.goo glegroups.com.. .

I am using .net frame work 1.0 with VS.net 2003. The file path is
defined by the command line. It doesn't matter it is a special folder
or not. if only the directory name contains a white space, like "C:\my
file\test.txt", "C:\test file\test.txt", the function
File.Exists(fil ePath) always return false, even the file exists in
that direcotry.
>
Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?
Thanks!- Hide quoted text -

- Show quoted text -

Feb 12 '07 #4
On Feb 12, 4:24 pm, "snow" <barbara_d...@y ahoo.comwrote:
On Feb 12, 1:01 pm, "Lloyd Sheen" <a...@b.cwrote: I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version are
you targeting?
LS
"snow" <barbara_d...@y ahoo.comwrote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .

I am using .net frame work 1.0 with VS.net 2003. The file path is
defined by the command line. It doesn't matter it is a special folder
or not. if only the directory name contains a white space, like "C:\my
file\test.txt", "C:\test file\test.txt", the function
File.Exists(fil ePath) always return false, even the file exists in
that direcotry.


Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?
Thanks!- Hide quoted text -
Do you have quotes around the path on the command line?

Feb 12 '07 #5
On Feb 12, 1:41 pm, z...@constructi on-imaging.com wrote:
On Feb 12, 4:24 pm, "snow" <barbara_d...@y ahoo.comwrote:


On Feb 12, 1:01 pm, "Lloyd Sheen" <a...@b.cwrote: I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version are
you targeting?
LS
"snow" <barbara_d...@y ahoo.comwrote in message
>news:11******* *************** @m58g2000cwm.go oglegroups.com. ..
I am using .net frame work 1.0 with VS.net 2003. The file path is
defined by the command line. It doesn't matter it is a special folder
or not. if only the directory name contains a white space, like "C:\my
file\test.txt", "C:\test file\test.txt", the function
File.Exists(fil ePath) always return false, even the file exists in
that direcotry.
Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?
Thanks!- Hide quoted text -

Do you have quotes around the path on the command line?- Hide quoted text -

- Show quoted text
Yes, I put quotes around the path, if the filePath = "C:\my_file
\test.txt", function File.exists(fil ePath) returns true; if I change
the filePath = "C:\my file\test.txt", and file exists,
File.Exists(fil ePath) returns false.

Feb 12 '07 #6
On Feb 12, 4:56 pm, "snow" <barbara_d...@y ahoo.comwrote:
On Feb 12, 1:41 pm, z...@constructi on-imaging.com wrote:


On Feb 12, 4:24 pm, "snow" <barbara_d...@y ahoo.comwrote:
On Feb 12, 1:01 pm, "Lloyd Sheen" <a...@b.cwrote: I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version are
you targeting?
LS
"snow" <barbara_d...@y ahoo.comwrote in message
news:11******** **************@ m58g2000cwm.goo glegroups.com.. .
I am using .net frame work 1.0 with VS.net 2003. The file path is
defined by the command line. It doesn't matter it is a special folder
or not. if only the directory name contains a white space, like "C:\my
file\test.txt", "C:\test file\test.txt", the function
File.Exists(fil ePath) always return false, even the file exists in
that direcotry.
Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?
Thanks!- Hide quoted text -
Do you have quotes around the path on the command line?- Hide quoted text -
- Show quoted text

Yes, I put quotes around the path, if the filePath = "C:\my_file
\test.txt", function File.exists(fil ePath) returns true; if I change
the filePath = "C:\my file\test.txt", and file exists,
File.Exists(fil ePath) returns false.
As others have said here, I have never had this problem and I use
File.Exists on paths with embedded spaces all the time. There is still
something you are not telling us about your scenario.

Feb 12 '07 #7
Please make sure that you don't have the quotes in the string you are
sending. I would advise to put up a msgbox just prior to the file.exists
call. I have never seen this fail.

LS
"snow" <ba**********@y ahoo.comwrote in message
news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
On Feb 12, 1:01 pm, "Lloyd Sheen" <a...@b.cwrot e:
>I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version
are
you targeting?

LS

"snow" <barbara_d...@y ahoo.comwrote in message

news:11******* *************** @m58g2000cwm.go oglegroups.com. ..

I am using .net frame work 1.0 with VS.net 2003. The file path is
defined by the command line. It doesn't matter it is a special folder
or not. if only the directory name contains a white space, like "C:\my
file\test.txt", "C:\test file\test.txt", the function
File.Exists(fil ePath) always return false, even the file exists in
that direcotry.
>>
Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?
Thanks!- Hide quoted text -

- Show quoted text -

Feb 12 '07 #8
On Feb 12, 1:57 pm, "Lloyd Sheen" <a...@b.cwrot e:
Please make sure that you don't have the quotes in the string you are
sending. I would advise to put up a msgbox just prior to the file.exists
call. I have never seen this fail.

LS"snow" <barbara_d...@y ahoo.comwrote in message

news:11******** **************@ j27g2000cwj.goo glegroups.com.. .
On Feb 12, 1:01 pm, "Lloyd Sheen" <a...@b.cwrot e:
I have lots of directories with that case and have never seen what you
describe. Ensure that the folder name is correct. What dot.net version
are
you targeting?
LS
"snow" <barbara_d...@y ahoo.comwrote in message
>news:11******* *************** @m58g2000cwm.go oglegroups.com. ..
I am using .net frame work 1.0 with VS.net 2003. The file path is
defined by the command line. It doesn't matter it is a special folder
or not. if only the directory name contains a white space, like "C:\my
file\test.txt", "C:\test file\test.txt", the function
File.Exists(fil ePath) always return false, even the file exists in
that direcotry.
Hi All,
I noticed if file path has a white space, for example "C:\my document
\test.txt", the function File.Exists(fil ePath) always return false in
release mode. How could I make this function work for the file which
is located in a direcotry with a white space?
Thanks!- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
Thanks for the advice. You are right, if I delete the quotes around
the file path on the command line, it works! but I still have the
problem in the following case. If I drag the file from the window
explorer and drop it to the program exe icon on the desktop, I still
got "File not Found", the reason is the file path was added quotes
automaticlly. How to make drag and drop the file work with white space
in the file path? I am using Microsoft.Visua lBasic.Command( ) to
capture the file path.

Feb 12 '07 #9
Either use the short path name or surround the filename with quotes as the
previous user suggested

--
Newbie Coder
(It's just a name)
Feb 13 '07 #10

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

Similar topics

0
1349
by: Masiar Farahani | last post by:
Hi, Is there a option in PythonWin to write files in unix file mode? Regards Masiar
2
12522
by: Rob Manger | last post by:
Hi Guys, Urgent problem. Trying to compile my solution I get the following error: Linking... LINK: fatal error LNK1181: cannot open input file 'Release\icmpping.abj' Note, I havn't changed anything. This project was developed on another computer that is setup exactly the same way.
1
1334
by: laurie | last post by:
Hi. Does anyone know of a simple asp script that can check free disk space and send an email to someone when low disk space occurs? I am not familiar with asp. I am from a php background but our server doesn't support php only asp. Thanks Laurie
4
20307
by: eva.monsen | last post by:
I'm trying to run a .BAT file using System.Diagnostics.Process. I'm having trouble getting Process.ExitCode to match up with what the .BAT file returns. Here are the contents of C:\temp\ConsoleApplication1\ConsoleApplication1\test1.bat: exit /B 6 Here is some C# code:
4
13447
by: Italian Pete | last post by:
Hi, I have a website sitting on a server (ServerA) with images to be displayed sitting on a separate server (ServerB) on the same network. I am trying to test for the existance of an image using: File.Exists(Server.Path("/images/" + "myImage.jpg") where the folder "images" is the virtual folder where the images are stored.
10
6643
by: ganeshp | last post by:
Below given is the code to check if a file exists. This code works on Windows but on Linux it fails even when the file exists. Please let me know if you have a solution or a work around for this. Has anybody experienced the same problem. boolean DoesTheFileExist(String filePath) { File fp = new File(filePath); if(true == fp.exists())
14
16364
by: Steve K. | last post by:
I have a method that I use to get a System.Drawing.Image from a file without keeping a handle on the file open (so I can delete the file). Here is the code: <code> public static Image ImageFromFileReleaseHandle(string filename) { FileStream fs = null; try {
10
1691
by: globalrev | last post by:
print os.path.exists('C:\Users\saftarn\Desktop\NetFlixDataSet \trainingsetunzipped\training_set\mv_0000001.txt') d=open('C:/Python25/myPrograms/mapexperiments/maps/provinces-of- sweden.gif') d.close() exists returns false but when i open it doesnt complain. how come? another file that exists returned false for complained when i tried to
1
1677
by: Samuel R. Neff | last post by:
I have a file in a directory that is returned from Directory.GetFiles() but subsequently fails a File.Exists() check. Test code: string p = @"C:\documents and settings\all users\" + @"application data\macromedia\fms"; foreach(string path in Directory.GetFiles(p)) { if ( ! File.Exists(path)) { foreach(char c in Path.GetFileName(path)) {
0
9456
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
10032
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...
1
9841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8712
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...
1
7244
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3805
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
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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.