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

S

snow

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!
 
N

Newbie Coder

Try this:

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

Lloyd Sheen

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
 
S

snow

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
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.
 
Z

zacks

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.

Do you have quotes around the path on the command line?
 
S

snow

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.

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

- Show quoted text[/QUOTE]

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.
 
L

Lloyd Sheen

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
 
Z

zacks

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.
 
S

snow

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.







- 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.
 
N

Newbie Coder

Either use the short path name or surround the filename with quotes as the
previous user suggested
 
L

Lloyd Sheen

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
 
S

snow

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







- Show quoted text -

Thanks! it works now.
 
L

Larry Linson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top