468,765 Members | 1,753 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

String.Format help (making a path)

I'm struggling to find a way to include long path names in a command
line argument string that I have to build at runtime.

I need to create a string like -o:"c:\my documents\my file.txt".

Everything I have tried so far causes the program I am calling to fail
(I know it can accept long file names as I have tried it from the
cmdline).

The problem I am having is using the Format command and getting "
(quotes) around the my file name.

I have tried

string strArgs = String.Format(@"-o:{3}{0}{3}",
strPatchName,
'"');

and

string strArgs = String.Format("-o:\"{0}\"",
strPatchName);

and
string strArgs = String.Format(@"-o:""{0}""",
strPatchName);

and none of it gives me a string like -o:"c:\my documents\my
file.txt". I keep getting strings like -o:\"c:\\my documents\\my
file.txt\" which doesnt work.

I've thought about converting the long file name to a short pathname,
which would work if the file exists (and in most cases it will not).

So, I am wondering if there is a better way to get this right?

Thnx
Matt
Nov 16 '05 #1
5 3656
could you do something like (untested)

string strArgs = "-o:\"" + strPatchName + "\"";

Take a look at the results outside of the debugger (print them to the
console yourself) as the debugger adds escape characters to strings.

raffelm wrote:
I'm struggling to find a way to include long path names in a command
line argument string that I have to build at runtime.

I need to create a string like -o:"c:\my documents\my file.txt".

Everything I have tried so far causes the program I am calling to fail
(I know it can accept long file names as I have tried it from the
cmdline).

The problem I am having is using the Format command and getting "
(quotes) around the my file name.

I have tried

string strArgs = String.Format(@"-o:{3}{0}{3}",
strPatchName,
'"');

and

string strArgs = String.Format("-o:\"{0}\"",
strPatchName);

and
string strArgs = String.Format(@"-o:""{0}""",
strPatchName);

and none of it gives me a string like -o:"c:\my documents\my
file.txt". I keep getting strings like -o:\"c:\\my documents\\my
file.txt\" which doesnt work.

I've thought about converting the long file name to a short pathname,
which would work if the file exists (and in most cases it will not).

So, I am wondering if there is a better way to get this right?

Thnx
Matt

--
to reply, remove .s.p.a.m. from email
Nov 16 '05 #2
Hm. I'm sure I've done stuff like this without any trouble before. Are you
sure that strPatchname doesn't already contain the double backslashes before
you get to this String.Format() call? The second example should work like a
champ.

If you can't get it to do so, though, I'd take the other poster's advice and
do a string concatenation or else a series of Append/AppendFormat calls to
an intermediate StringBuilder.

--Bob
"raffelm" <ma*********@mindspring.com> wrote in message
news:ba**************************@posting.google.c om...
I'm struggling to find a way to include long path names in a command
line argument string that I have to build at runtime.

I need to create a string like -o:"c:\my documents\my file.txt".

Everything I have tried so far causes the program I am calling to fail
(I know it can accept long file names as I have tried it from the
cmdline).

The problem I am having is using the Format command and getting "
(quotes) around the my file name.

I have tried

string strArgs = String.Format(@"-o:{3}{0}{3}",
strPatchName,
'"');

and

string strArgs = String.Format("-o:\"{0}\"",
strPatchName);

and
string strArgs = String.Format(@"-o:""{0}""",
strPatchName);

and none of it gives me a string like -o:"c:\my documents\my
file.txt". I keep getting strings like -o:\"c:\\my documents\\my
file.txt\" which doesnt work.

I've thought about converting the long file name to a short pathname,
which would work if the file exists (and in most cases it will not).

So, I am wondering if there is a better way to get this right?

Thnx
Matt

Nov 16 '05 #3
raffelm wrote:
I keep getting strings like -o:\"c:\\my documents\\my
file.txt\" which doesnt work.


Are you sure that's what you are getting, or is that just what being
displayed in the debug window? (That *would* be what is displayed in the
debug window if the string was what you wanted)

--
Truth,
James Curran [MVP]
www.NJTheater.com (Professional)
www.NovelTheory.com (Personal)


Nov 16 '05 #4
Hi raffelm,

All of them works just fine. The only thing I can think of is that you
already have those double backslashes in the strPatchName

--

Stoitcho Goutsev (100) [C# MVP]
"raffelm" <ma*********@mindspring.com> wrote in message
news:ba**************************@posting.google.c om...
I'm struggling to find a way to include long path names in a command
line argument string that I have to build at runtime.

I need to create a string like -o:"c:\my documents\my file.txt".

Everything I have tried so far causes the program I am calling to fail
(I know it can accept long file names as I have tried it from the
cmdline).

The problem I am having is using the Format command and getting "
(quotes) around the my file name.

I have tried

string strArgs = String.Format(@"-o:{3}{0}{3}",
strPatchName,
'"');

and

string strArgs = String.Format("-o:\"{0}\"",
strPatchName);

and
string strArgs = String.Format(@"-o:""{0}""",
strPatchName);

and none of it gives me a string like -o:"c:\my documents\my
file.txt". I keep getting strings like -o:\"c:\\my documents\\my
file.txt\" which doesnt work.

I've thought about converting the long file name to a short pathname,
which would work if the file exists (and in most cases it will not).

So, I am wondering if there is a better way to get this right?

Thnx
Matt

Nov 16 '05 #5
After I printed it out to the output tab, I was able to make a change
in the format string and the command worked.

The debugger really is deceptive for these types of debugging.

"Bob Grommes" <bo*@bobgrommes.com> wrote in message news:<e0**************@TK2MSFTNGP11.phx.gbl>...
Hm. I'm sure I've done stuff like this without any trouble before. Are you
sure that strPatchname doesn't already contain the double backslashes before
you get to this String.Format() call? The second example should work like a
champ.

If you can't get it to do so, though, I'd take the other poster's advice and
do a string concatenation or else a series of Append/AppendFormat calls to
an intermediate StringBuilder.

--Bob
"raffelm" <ma*********@mindspring.com> wrote in message
news:ba**************************@posting.google.c om...
I'm struggling to find a way to include long path names in a command
line argument string that I have to build at runtime.

I need to create a string like -o:"c:\my documents\my file.txt".

Everything I have tried so far causes the program I am calling to fail
(I know it can accept long file names as I have tried it from the
cmdline).

The problem I am having is using the Format command and getting "
(quotes) around the my file name.

I have tried

string strArgs = String.Format(@"-o:{3}{0}{3}",
strPatchName,
'"');

and

string strArgs = String.Format("-o:\"{0}\"",
strPatchName);

and
string strArgs = String.Format(@"-o:""{0}""",
strPatchName);

and none of it gives me a string like -o:"c:\my documents\my
file.txt". I keep getting strings like -o:\"c:\\my documents\\my
file.txt\" which doesnt work.

I've thought about converting the long file name to a short pathname,
which would work if the file exists (and in most cases it will not).

So, I am wondering if there is a better way to get this right?

Thnx
Matt

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Neil Schemenauer | last post: by
3 posts views Thread by Ryan Folstad | last post: by
32 posts views Thread by tshad | last post: by
18 posts views Thread by WStoreyII | last post: by
21 posts views Thread by Hitesh | last post: by
11 posts views Thread by RipperT | last post: by
4 posts views Thread by Tim Kelley | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.