0

So i have this lil .bat setup

@ECHO OFF
echo %date%
Copy D:\000Back\list.txt D:\111Back\
CD D:\111Back\
copy list.txt %date%_%time%.txt
ECHO done
PAUSE

The second copy command never goes through, that might be because are there dots(.) in the date and time? So, it cannot rename it?

I'm trying to make a .bat file that will make backups for me, so having them named the day they are made would be great.

Thanks if you can help, there's probably a really easy solution, but im really only just dipping my toes into doing stuff like this.

1

There is a very simple solution, use Powershell instead of the antiquated command prompt:

Copy-Item D:\000Back\list.txt ("D:\111Back\" + (get-date -format "yyyyMMdd_HHmm") + ".txt")

It's a oneliner.

| improve this answer | |
0

Using *.bat file you can do this:

@ECHO OFF
Copy D:\000Back\list.txt D:\111Back\
CD D:\111Back\
set mydate=%date:/=%
set mytime=%time::=-%
set mytimestamp=%mydate: =_%_%mytime:.=_%
copy list.txt "%mytimestamp%.txt"
ECHO done
PAUSE
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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