0

Let's say, the user drag and drops an file into my batch file, which causes that the batch file copies the file to a certain directory. the problem is the following command:

copy "%1" "C:\path\to\it"

The problem here is the quotes around%1. When you drag and drop something in a batch file, normally, it wouldn't put quotes, so everything's fine. But when i convert my batch file to EXE, it actually puts quotes there.

So, what i want to do is, checking if the file does have quotes, if not, than do the command above, otherwise, do the command without quotes.

Thanks.

Deniz Zoeteman
  • 9,691
  • 26
  • 70
  • 97

3 Answers3

2

Would the following work?

copy %1 "C:\Dir1\Dir2"

my few attempts to find a problem not quoting %1 have not resulted in adverse effects.

shroudednight
  • 605
  • 4
  • 16
  • +1. Actually, file names with spaces always get passed with quotes and those quotes *are* part of the argument. Putting quotes around `%1` is usually superfluous. This doesn't have to be related to the batch to exe converter. – Joey Jan 02 '10 at 17:46
1

Not sure if the answer given here was what you were seeking, and I may be a couple of years late, but I would like to offer an alternate solution to your quoting problem as I have run into it something similar myself. Maybe it will benefit someone else.

You ARE able to strip the quotes from around variables, including the ones that are dragged and dropped. Here's how:

  • add a tilde to the %n variable (e.g., copy %~1 "C:\path\to\it")

For other variables within the batch file, use a similar technique, this time performing a substitution of the double-quote for nothing :"=, as in:

set filename="C:\path\to\it"
echo %filename% (will give you "C:\path\to\it") 
set noquotefilename=%filename:"=%
echo %noquotefilename% (will give you C:\path\to\it without the quotes)

It is not my original solution, but I found it near the bottom of the following post:

Removing double quotes from variables in batch file creates problems with CMD environment

The substitution technique has other applications, as you could easily substitute any character for any other (e.g., :\=_ to substitute a back-slash for an underscore).

Hope this helps!

Community
  • 1
  • 1
0

The problem is the process by which you are converting to EXE. Try a different BAT to EXE converter.