boushta
here i dragged 4 files on a batch file,here is the output of cmdcmdline variable
Code: Select all
@echo off
echo %cmdcmdline%
C:\Windows\system32\cmd.exe /c ""C:\Users\boushta\Desktop\test.cmd" D:\wxchjfg.txt D:\w&xc.txt D:\dl.txt"
Code: Select all
C:\Windows\system32\cmd.exe /c ""C:\Users\boushta\Desktop\test.cmd" "D:\wxchjfg.txt" "D:\w&xc.txt" "D:\dl.txt""
note that i dragdroped those files on a batch file not passed them manually
Last edited by boushta (11 Feb 2015 14:39)
----------------------------
#209 Feb 2015 21:20
bluesxman
If you're just after the passed files, they are all present in the special variable %*. You can do this to quote them and store in a variable:
Code: Select all
@echo off
set "files="
for %%F in (%*) do (
if not defined files (
set "files="%%~F""
) else (
call set "files=%%files%% "%%~F""
)
)
set files
Last edited by bluesxman (09 Feb 2015 21:26)
cmd | *sh | ruby | chef
----------------------------
#310 Feb 2015 07:35
foxidrive
Note that drap and drop fails in Windows if the file or folder contains an & character and has no spaces or long filename elements.
If you explain the task then you may get better solutions, as everything to do with batch relies on the exact task - or you may get an answer but it will fail in different circumstances.
Run this and then drag the file on top of the batch file to see.
Code: Select all
@echo off
echo(%*
echo done
pause
break >"one-two-&-three.txt"
#410 Feb 2015 16:32
boushta
thanks for replies but none of the solution worked because of the ampersand "&" char
again i dragged the following files all simultaneously on the batch file
Code: Select all
D:\the-best-slide-there.jpg
D:\1xc&qsd.txt
D:\kjh.txt
bluesxman
Code: Select all
files="D:\the-best-slide-there.jpg" "D:\1xc"
Code: Select all
"D:\the-best-slide-there.jpg" D:\1xc
as you can see any string after the ampersand is truncated
hopefully i didn't get a cmd crash this time using your code when i drag a file containing an ampersand , unfortunately the output can not complete
i do not think there is a way other than using cmdcmdline variable, because i thinks this is the only variable that preserve & in dragged params
sadly it does not surround by quotes dragged files which do not contain space
and even if the cmdcmdline var is the only way,it is really hard to manipulate it to give you the wanted result
please is there any way around to preserve all dragged files even if & exist
----------------------------
#510 Feb 2015 19:15
Liviu
Dave Benham's code at https://stackoverflow.com/questions/854 ... ampersands … ampersands will work for some "&^!" poison chars, but still fail with the default batch separators for example "1=2;3,4.txt". I don't know of a foolproof pure batch solution, and it may be easier to just write a VBS or JS wrapper to (at least) parse the command line.
----------------------------
#610 Feb 2015 20:54
boushta
it works for ampersand but still it will create another problem
it is a pity
please how to write a js wrapper if this can solve the problem and finally pass the full arguments throught a js file
----------------------------
#710 Feb 2015 23:51
Liviu
drop.jsboushta wrote:
it works for ampersand but still it will create another problem
It doesn't _create_ it, it just doesn't solve it. The same problem exists with other approaches that rely on the builtin command line parsing.
boushta wrote:
please how to write a js wrapper if this can solve the problem and finally pass the full arguments throught a js file
Code: Select all
var sCmd = '%comspec% /c '
+ WScript.CreateObject("Scripting.FileSystemObject")
.GetParentFolderName(WScript.ScriptFullName)
+ '\\drop.cmd';
var vArgs = WScript.Arguments;
for(var n = 0; n < vArgs.length; n++) sCmd += ' "' + vArgs(n)+ '"';
WScript.CreateObject("WScript.Shell").Run(sCmd);
Code: Select all
@echo off
for %%v in (%*) do echo %%v
pause
----------------------------
#811 Feb 2015 14:40
boushta
it works