0

I made a batch file that receives one of its parameters from right-clicking on a file and sending it to my batch file. The problem is that it crashes if the path has a space in it. For example, a file in C:\temp\CarRide works, but a file in C:\temp\Car Ride doesn't work. The cmd window flashes and immediately closes. I tried putting a pause as the first line in the batch file, and it didn't event get to that, so I'm pretty sure the problem is the way Send To handles the path. Got any ideas?

AaronK
  • 1
  • 4
    Without seeing how you treat the command line arguments (quoting) in your batch it's difficult to decide where the problem is. Show your code in a [mcve] –  Jun 07 '18 at 17:12
  • We may also need to see the registry `..\shell\..\command` entry you made for the right click option too. – Compo Jun 07 '18 at 18:28
  • In your batch file reference the passed file name always with `"%~1"`. Run in a command prompt window `call /?` to get output the help for this command which explains how batch file arguments can be referenced. And help output running `cmd /?` explains that a file/folder name (or any other argument string) must be enclosed in double quotes on containing a space or of these characters ``&()[]{}^=;!'+,`~`` or the redirection operators `<|>` which can't exist in a file/folder name. – Mofi Jun 07 '18 at 18:47

1 Answers1

1

Use quotes when there is a space in the Path C:\temp\CarRide vs. "C:\temp\Car Ride", otherwise the path is parsed as two arguments. In your case the first the right clicked file takes the first argument %1 so set input to "%1"

NSO
  • 11
  • 2