I am actually pretty new to this batch file thing. I know it’s important to know at least the basic commands. How do I do the following?
- Zipping a specified folder.
- Move the folder to another place.
- When zipping it, the ZIP file name will be the current date and
if there is another zipped file with the same name, it should be named like 20090924-2.
PS: 7-Zip is installed on my computer as an archive software.
The batch script listed below will do it (I have tested it
and it works to specifications). The directory to zip and
move is specified as its parent directory and the name of
the directory (PARENT_FOLDERTOZIP and FOLDERTOZIP in the
beginning) – I couldn’t figure out how to copy entire
directories (I think XCOPY can only copy content of
directories and sub-directories.). The copy location is
specified as FOLDERTARGETLOCATION, and the directory to place
the compressed files in is specified as ZIPDIR.
The location of 7-Zip is configured through SEVENZIP_EXE.
Note also that getting the current date in the required
format depends on the short date format in regional
settings. I have listed three different versions for
ISO-8601, Central European and U.S.A. The active one in the
listing is for the U.S.A. (the “set FDATE=” line). If a
different one is needed then just copy-paste from one of the
other two.
That said it should be noted that this kind of thing is much
easier with Perl, Python or PowerShell.