473,240 Members | 1,612 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,240 software developers and data experts.

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 3851
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Neil Schemenauer | last post by:
The title is perhaps a little too grandiose but it's the best I could think of. The change is really not large. Personally, I would be happy enough if only %s was changed and the built-in was...
3
by: Ryan Folstad | last post by:
Hello i have a problem with c# string handling. Hopefully someone can explain what im doing wrong. this code: string windowsdir = "c:\\windows"; string installdir ="c:\\install"; string path=...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
18
by: WStoreyII | last post by:
I am making a asp page that will run on my computer by iis. But the problem is the database in on a web server. I can not seem to get the connection to work for it though here his the connection...
3
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
21
by: Hitesh | last post by:
Hi, I get path strings from a DB like: \\serverName\C:\FolderName1\FolderName2\example.exe I am writing a script that can give me access to that exe file. But problem is that string is not...
11
by: RipperT | last post by:
Don't know if this group covers web apps, but here goes. In VS 2005, I am trying to get variables to hold thier values during postback from the server. I convert a text box's user-keyed value to an...
4
by: Tim Kelley | last post by:
I am reading a text file with a streamreader. I parse out path and need to use that path in a sql statement. The path is in the file as \\servername\share\folder\filename.txt. When the line is...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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...

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.