drag'n drop fileName with a caret

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

drag'n drop fileName with a caret

#1 Post by Ed Dyreen » 03 Nov 2012 19:43

'
When working on this file I noticed I couldn't handle a drag'n drop fileName with a caret.
I know batch can't handle many special chars, but a caret :shock:

drag'n drop 'no^Caret.TST' -> 'can'tDo.CMD'

Code: Select all

echo.%*
echo."%~*"
echo.%1
echo."%~1"
pause

jeb
Expert
Posts: 1062
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: drag'n drop fileName with a caret

#2 Post by jeb » 04 Nov 2012 01:19

Hi ED,

as Drag&Drop is a bit strange implmented with batch, it's not safe to use %1, %2...
As you can see the carets are a bit problematic, but this&taht.txt will kill your batch file completly.

The best way I know, is to use !cmdcmdline! to access the drag&drop files and exit the batch explicitly with EXIT

Drag and drop batch file for multiple files?

jeb

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: drag'n drop fileName with a caret

#3 Post by foxidrive » 04 Nov 2012 04:21

Ed Dyreen wrote:'
When working on this file I noticed I couldn't handle a drag'n drop fileName with a caret.
I know batch can't handle many special chars, but a caret :shock:

drag'n drop 'no^Caret.TST' -> 'can'tDo.CMD'

Code: Select all

echo.%*
echo."%~*"
echo.%1
echo."%~1"
pause


FWIW this syntax error kills the batch file completely in Win8.

The following usage of the path operator in batch-parameter
substitution is invalid: %~*"



^ is as bad as % in batch files.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: drag'n drop fileName with a caret

#4 Post by Ed Dyreen » 04 Nov 2012 17:35

'
That should work :D ( I will test it shortly )

Jeb, thanks once more !

Post Reply