I want to write a batch job that when executed will grab all the files in the C:\Test\Log
folder and move them to a new directory in the C:\Test
. This new directory will have a name called "Backup-" and CURRENT DATE.
So once completed, the log folder should be empty with all the files now located in the new folder.
I know I would have to use the MOVE
command, but have no idea how to dynamically create a new folder, and use the date to name it.
Something like this might help:
The important part is the first line. It takes the output of the internal
DATE
value and parses it into an environmental variable namedToday
, in the formatCCYYMMDD
, as in '20110407`.The
%Date:~10,4%
says to extract a *substring of theDate
environmental variable 'Thu 04/07/2011' (built in - typeecho %Date%
at a command prompt) starting at position 10 for 4 characters (2011
). It then concatenates another substring ofDate:
starting at position 4 for 2 chars (04
), and then concats two additional characters starting at position 7 (07
).*The substring value starting points are 0-based.
You may need to adjust these values depending on the date format in your locale, but this should give you a starting point.
this will also work, if you like