0

I try to make a batch file that will create a back-up folder of my game every time I close it but when i try it it just say that my destination name is invalid here's what I tried:

set name='\save\world|%date%-%time%'
echo R | xcopy world %name% /E/H
pause
lolozen
  • 386
  • 1
  • 4
  • 19
  • 2
    a) single quotes do nothing special in batch - they are just like any character. b) `|` isn't a valid character for a file name. c) your `date` and `time` variables probably also contain characters that are not valid in file names. – Stephan Jul 15 '19 at 18:13

2 Answers2

0

You can use "for" to parse the tokens in a string, command, or directory listing. the "for" command winds up doing much of the heavy lifting in batch files.

for /f "Tokens=1-4 Delims=:. " %%i in ("%time%") do set tm=%%i.%%j.%%k.%%l
for /f "Tokens=1-4 Delims=/ " %%i in ("%date%") do set dt=%%l.%%j.%%k
set bkupname=\temp\save\world-%dt%.%tm%\
xcopy world %bkupname% /E /H
0

Thanks like Stephan said

a) single quotes do nothing special in batch - they are just like any character. b) | isn't a valid character for a file name. c) your date and time variables probably also contain characters that are not valid in file names.

so here's what I did and it works so thanks

set name="world %date:~0,2% %date:~3,2% %date:~8,2% %time:~0,2%h%time:~3,2%"
echo R | xcopy world .\save\worldtemp /E/H
move .\save\worldtemp .\save\%name%
pause
lolozen
  • 386
  • 1
  • 4
  • 19
  • 1
    you should enclose path/file names in double-quotes to correctly process spaces: `move ".\save\worldtemp" ".\save\%name%"` – Stephan Jul 15 '19 at 18:50
  • 1
    and see [here](https://stackoverflow.com/a/18024049/2152082) for a better method to get the date/time string. – Stephan Jul 15 '19 at 19:04