2

I'm trying to do a quick and simple game backup script and it's not working for me. Here's what I have.

   @echo off

:main

RD /S /Q "C:\Users\Citadel\Desktop\Minecraft_Backups"

mkdir "C:\Users\Citadel\Desktop\Minecraft_Backups\%date% - %time%"

XCOPY "C:\Users\Citadel\AppData\Roaming\.minecraft\saves" "C:\Users\Citadel\Desktop\Minecraft_Backups\%date% - %time%" /D /E /C /R /I /K /Y

echo %date% - %time% - Backup Complete >> log.txt

PING 1.1.1.1 -n 1 -w 900000 >NUL

goto main

Honestly the mkdir command was a shot in the dark, but nothing so far has worked so I tried it.

2
  • Well it's an example of a problem I've been having for a while. Can't get any backup scripts to work since I use this format for all of them and just retrofit it. Commented May 14, 2012 at 20:55
  • Because I'm not that good at programming and batch can do the job while being easily editable at the same time. I'd write it in Python, but again, I don't know how to make a folder using the date and time. Commented May 14, 2012 at 20:58

2 Answers 2

3

The problem is that %date% and %time% contain special characters that can't be used in directory names. Try this at the top of your script:

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)

Or if you prefer 24-hour time, change the second line to:

for /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)

And then use %mydate%_%mytime% in place of %date% %time%.

Note that this may have regional issues, but if you confirm it working for your machine, for local backups it will always be fine.

1
  • Thanks. I'd vote up but I don't have the rep for it. XD Very helpful. Commented May 14, 2012 at 21:08
0

Here's what I found that seems to work:

@setlocal enableextensions
set datestamp=%date:~-4,4%%date:~-10,2%%date:~7,2%
mkdir %datestamp%
1
  • this does not include time Commented Nov 10, 2016 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.