Referencing file path-need help with spaces
Posted: 02 Jun 2015 20:40
This batch file runs okay in c:\Temp.
When I move it to C:\Test Folder, messages say
the system cannot find the path specified.
and the batch file continues but does not do what is expected, sorting a list in random order.
I know it is because of the space. How do I fix it?
Thanks.
When I move it to C:\Test Folder, messages say
the system cannot find the path specified.
and the batch file continues but does not do what is expected, sorting a list in random order.
I know it is because of the space. How do I fix it?
Thanks.
Code: Select all
@Echo Off
setlocal enabledelayedexpansion
::random sorting
Set thisPath=%~dp0
Set creaturesList=%thisPath%original.txt
Set rsortedList=%thisPath%rsorted.txt
If EXIST %creaturesList% DEL %creaturesList%
For %%a In (Aardvark Beetle Cat Dog Emu Frog Gopher Hamster Iguana) Do (Echo %%a>>%creaturesList%)
Call:sortRandom %creaturesList% %rsortedList%
Echo.& Echo original list:& Echo.
For /F %%a In (%creaturesList%) Do (
Echo %%a
)
Echo.& Echo random sorted:
Echo.& Type %rsortedList%& Echo.
exit /b
:sortRandom
setlocal enabledelayedexpansion
Type NUL>tmp.txt
For /F %%a In (%~1) Do (
Set rndVar=!RANDOM!
Set rndVar=0000!rndVar!
Set rndVar=!rndVar:~-5!
Echo !rndVar! %%a>>tmp.txt
)
SORT tmp.txt>sorted.txt
Type NUL>%2
For /F "tokens=1,2* delims= " %%a In (sorted.txt) Do (
Echo %%b>>%2
)
DEL sorted.txt
DEL tmp.txt
endlocal & exit /b
endlocal