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.

kofemann
  • 4,626
  • 1
  • 25
  • 30
Csupi
  • 1

2 Answers2

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.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
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
maar
  • 485
  • 6
  • 20