Michel Keijzers
Michel Keijzers

Reputation: 15357

Seeing multiple arguments in C# arguments as one for folder/name containing spaces?

When I double click a certain file the arguments for the launched application are according to Process Explorer:

"C:\Program Files (x86)\MiKeSoft\PCG Tools\PcgTools.exe" debug D:\Muziek\Korg\Workstations\Kronos\Sounds and Templates_Commercial\KRS\KRS-03\KRS-03.PCG

Is there an easy way to see the arguments containing the file name (after debug) as one string (without parsing / combining / extracting all possibilities manually)?

Reason: there can be more files (with or without spaces in them).

What I get as arguments is:

argument 0: "C:\Program Files (x86)\MiKeSoft\PCG Tools\PcgTools.exe"
argument 1: debug
argument 2: D:\Muziek\Korg\Workstations\Kronos\Sounds
argument 3: and 
argument 4: Templates\_Commercial\KRS\KRS-03\KRS-03.PCG

What I want is:

argument 0: "C:\Program Files (x86)\MiKeSoft\PCG Tools\PcgTools.exe"
argument 1: debug
argument 2: "D:\Muziek\Korg\Workstations\Kronos\Sounds and Templates\_Commercial\KRS\KRS-03\KRS-03.PCG"

i.e. I want automatic " around the strings and have them combined. It is easy in this case but when having multiple files it can be tricky.

Note: This is not the problem about the Debug parameter (see Double clicking a file gives "debug" as second parameter?) although the same example is used.

Upvotes: 0

Views: 308

Answers (2)

Raymond Chen
Raymond Chen

Reputation: 45173

Your file type registration did not put quotation marks around the argument. If you want the argument quoted, you must provide the quotation marks. Windows is just following the instructions you provided.

"C:\Program Files (x86)\MiKeSoft\PCG Tools\PcgTools.exe" debug "%1"

Note the quotation marks around %1.

Upvotes: 2

user2275929
user2275929

Reputation: 15

Look at this examples:

C:\development\abkcmd\abkcmd\bin\Debug>abkcmd.exe one "two parms" 3
Number of command line parameters = 3
Arg[0] = [one]
Arg[1] = [two parms]
Arg[2] = [3]


C:\development\abkcmd\abkcmd\bin\Debug>abkcmd.exe one two parms 3
Number of command line parameters = 4
Arg[0] = [one]
Arg[1] = [two]
Arg[2] = [parms]
Arg[3] = [3]


C:\development\abkcmd\abkcmd\bin\Debug>abkcmd.exe one two 'parms' 3
Number of command line parameters = 4
Arg[0] = [one]
Arg[1] = [two]
Arg[2] = ['parms']
Arg[3] = [3]

You can do this with this code:

Console.WriteLine("Number of command line parameters = {0}", args.Length);
        for (int i = 0; i < args.Length; i++)
        {
            Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
        }

        Console.ReadLine();

Upvotes: 1

Related Questions