473,503 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File.Exists(filePath) 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(filePath) 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 4520
Try this:

Dim strPath As String =
Environment.GetFolderPath(Environment.SpecialFolde r.Personal).ToString
Dim strFile As String = IO.Path.Combine(strPath, "Test.txt")
MessageBox.Show(IO.File.Exists(strFile).ToString)

--
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**********@yahoo.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
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 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.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...@yahoo.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.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(filePath) 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(filePath) 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...@yahoo.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...@yahoo.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.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(filePath) 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(filePath) 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...@construction-imaging.com wrote:
On Feb 12, 4:24 pm, "snow" <barbara_d...@yahoo.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...@yahoo.comwrote in message
>news:11**********************@m58g2000cwm.googleg roups.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(filePath) 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(filePath) 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(filePath) returns true; if I change
the filePath = "C:\my file\test.txt", and file exists,
File.Exists(filePath) returns false.

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


On Feb 12, 4:24 pm, "snow" <barbara_d...@yahoo.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...@yahoo.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.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(filePath) 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(filePath) 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(filePath) returns true; if I change
the filePath = "C:\my file\test.txt", and file exists,
File.Exists(filePath) 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**********@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
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...@yahoo.comwrote in message

news:11**********************@m58g2000cwm.googleg roups.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(filePath) 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(filePath) 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.cwrote:
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...@yahoo.comwrote in message

news:11**********************@j27g2000cwj.googlegr oups.com...
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...@yahoo.comwrote in message
>news:11**********************@m58g2000cwm.googleg roups.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(filePath) 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(filePath) 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.VisualBasic.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
I think that all you need to do is replace all " in the command argument
with string.empty.

A quote is not a valid character for folder or file names so you can do this
and it should work correctly.

LS

"snow" <ba**********@yahoo.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
On Feb 12, 1:57 pm, "Lloyd Sheen" <a...@b.cwrote:
>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...@yahoo.comwrote in message

news:11**********************@j27g2000cwj.googleg roups.com...
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...@yahoo.comwrote in message
>>news:11**********************@m58g2000cwm.google groups.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(filePath) 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(filePath) 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.VisualBasic.Command() to
capture the file path.
Feb 13 '07 #11
On Feb 12, 4:23 pm, "Lloyd Sheen" <a...@b.cwrote:
I think that all you need to do is replace all " in the command argument
with string.empty.

A quote is not a valid character for folder or file names so you can do this
and it should work correctly.

LS

"snow" <barbara_d...@yahoo.comwrote in message

news:11**********************@v45g2000cwv.googlegr oups.com...
On Feb 12, 1:57 pm, "Lloyd Sheen" <a...@b.cwrote:
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...@yahoo.comwrote in message
>news:11**********************@j27g2000cwj.googleg roups.com...
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...@yahoo.comwrote in message
>news:11**********************@m58g2000cwm.googleg roups.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(filePath) 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(filePath) 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.VisualBasic.Command() to
capture the file path.- Hide quoted text -

- Show quoted text -
Thanks! it works now.

Feb 13 '07 #12

I am so sorry; call me ignorant

can you even use the 1.0 framework with VS.net 2003?

grow a clue, kid

DOTNET sucks a big fat hairy cock and MS is preparing 'yet another
visual fred'

now is the time for action, kids
LIFE IS DOTNOT PEACHY

On Feb 12, 1:24 pm, "snow" <barbara_d...@yahoo.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...@yahoo.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.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(filePath) 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(filePath) 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 -

Feb 14 '07 #13

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

Similar topics

0
1340
by: Masiar Farahani | last post by:
Hi, Is there a option in PythonWin to write files in unix file mode? Regards Masiar
2
12483
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...
1
1310
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...
4
20260
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...
4
13417
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...
10
6622
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....
14
16302
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...
10
1669
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')...
1
1660
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\" +...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
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,...
0
7342
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...
0
7464
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...
0
5586
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,...
1
5018
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...
0
4680
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...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.