C# - Easiest way to parse filename with spaces eg. “C:\Test\File with spaces.txt”

前端 未结 6 2217
孤独总比滥情好
孤独总比滥情好 2021-01-04 23:30

I am trying to pass a full file path to FFMPEG.

C:\\TestFolder\\Input\\Friends - Season 6 - Gag Reel.avi

and it\'s obviously not liking th

6条回答
  •  离开以前
    2021-01-04 23:48

    In general, file paths passed as arguments on the command line require the path to be surrounded with quotation marks.

    If you're talking about accepting file paths as an argument to your program, it's easiest to require users to quote paths. That way, the args argument to your main method will contain the whole path as a single string.

    If you're calling other programs and passing arguments, file paths with spaces must be quoted.

    Process p = new Process();
    p.StartInfo.FileName = "notepad.exe";
    p.StartInfo.Arguments = string.Format("\"{0}\"", filePath);
    p.Start();
    

提交回复
热议问题