Reputation: 51
I have to do a task where in //Traning/Biz having some xml file with prefix naming Current day, like 201504140157034_{hgds}.xml. I need to create a Batch script which can create a zip file with current date name on same network folder and zip all current day files to that.
I have found bellow code, please help me do make it happen
Thanks in advance :)
@echo off
:: variables
set drive=G:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"
echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"
echo ### Backing up email and address book (Outlook Express)...
%backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"
echo ### Backing up email and contacts (MS Outlook)...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"
echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"
:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."
Upvotes: 0
Views: 580
Reputation: 1660
Both winzip and 7z have command line capabilities. I'd suggest if you don't have one already installed, download 7z (cause it's free). Then you just need to know how to copy the right xml files across, before finally zipping it all up.
rem to get the date in yyyyMMdd format
for /f %%a in ('wmic os get LocalDateTime ^| findstr [0-9]') do set dt=%%a
set dt=%dt:~0,8%
%backupcmd% \\Traning\Biz\%dt%*.xml "%drive%\XML"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip -pSomePassword "%zipFileName%" "%drive%\*.*"
Omit the -tzip to get a native 7z archive instead of winzip.
Have a look at examples for 7z here: http://www.dotnetperls.com/7-zip-examples
Upvotes: 1