Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle spaces in file path if the folder contains the space?

public static void launchProcess(string processName, string arguments, out string output)
{
    Process p = new Process
    {
        StartInfo = { UseShellExecute = false, RedirectStandardOutput = true, FileName = processName, Arguments = arguments }
    };

    p.Start();
    output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();

}

And if my arguments contains the file names like:

D:\Visual Studio Projects\ProjectOnTFS\ProjectOnTFS

Then I get the error:

like image 782
vakas Avatar asked Jun 29 '11 13:06

vakas


People also ask

How do you handle spaces in a file path?

Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified. The quotation marks must be used.

How do you handle a space in a batch file?

When you send arguments, those with poison or space characters need to be doublequoted. Inside your batch file, if you no longer need the surrounding doublequotes, you'd remove them by using %~5 instead of %5 . Additionally the recommended syntax for the set command is Set "VariableName=VariableValue" .

How do you handle spaces in CMD?

Enclose the paths containing spaces with double quotes.


1 Answers

It'll need doubles quotes, but will also likely need an @ to treat the string word-for-word (verbatim string) i.e. the "\" has a special meaning in string e.g. \t means a tab, so we want to ignore the \

So not only the double quotes, but also @

string myArgument = @"D:\Visual Studio Projects\ProjectOnTFS\ProjectOnTFS";
like image 74
Alex KeySmith Avatar answered Sep 20 '22 20:09

Alex KeySmith