This is a positive first post.
It’s a batch file I wrote to do some backup stuff.
It has only been tested on XP, but will almost surely work on Win2k (ooooh!) not sure about Win9x, Me, 3.x, DOS, etc, etc.
I’d love to make it smarter, and will no doubt post some moanings about things I can’t do in the coming days, but this is a positive start :)
ps. Keep in mind that as far as batch files go, I’m a beginning beginner, who’s like just begun…
rem -------------------------------------------------
rem This script copies xls, doc, txt files from 2
rem specified source directories to a specified
rem target directory. It then moves the files in
rem the target directory to a ZIP file in the same
rem target directory.
rem -------------------------------------------------
ECHO OFF
ECHO --------------------------------------
ECHO Initialise Directory variables.....
ECHO --------------------------------------
rem Set a target Directory, which will be created
rem if it does not exist.
set myTargetDir=C:\BackupsECHO "myTargetDir = %myTargetDir%"
rem Set 2 source directories
rem If you just want 1 directory, remove the references
rem to the 2nd one here and below
set mySourceDir1=C:\My Work
set mySourceDir2=D:\My Emails
ECHO ------------------------------
ECHO Initialise variables.....
ECHO ------------------------------
rem Set a standard prefix for all your zip files
set myZipPrefix=My_Work_Backup
rem Create a unique string based on date-time and make
rem this the suffix for the zip file that will be
rem created in this run.
set myZipSuffix=%DATE:~9,2%%DATE:~6,2%%DATE:~3,2%-%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%
ECHO ----------------------------------------
ECHO Create target directory if needed....
ECHO ----------------------------------------
rem If the target directory does not exist create
rem it (dir name is based on date)
IF NOT EXIST "%myTargetDir%\%date%" md "%myTargetDir%\%date%"
ECHO ----------------------------------------------
ECHO Copy files from source dir 1 to target....
ECHO ----------------------------------------------
rem Copy all Excel worksheets from source directory
rem to target directory
copy "%mySourceDir1%\*.xls" "%myTargetDir%\%date%"
rem Copy all Word docs from source directory to target
rem directory
copy "%mySourceDir1%\*.doc" "%myTargetDir%\%date%"
rem Copy all TXT files from source directory to target
rem directory
copy "%mySourceDir1%\*.txt" "%myTargetDir%\%date%"
ECHO ----------------------------------------------
ECHO Copy files from source dir 2 to target....
ECHO ----------------------------------------------
rem Get some more Word docs from a local directory
copy "%mySourceDir2%\*.doc" "%myTargetDir%\%date%"
rem Get some more Excel docs from a local directory
copy "%mySourceDir2%\*.xls" "%myTargetDir%\%date%"
rem Get some more TXT files from a local directory
copy "%mySourceDir2%\*.txt" "%myTargetDir%\%date%"
ECHO --------------------------------------------
ECHO ZIP all xls, doc, txt files in target....
ECHO --------------------------------------------
rem Move all Excel worksheets from taget directory to
rem a Zip file in the target directory
zip -m9o "%myTargetDir%\%date%\%myZipPrefix%_%myZipSuffix%.zip" "%myTargetDir%\%date%\*.xls"
rem Move all Word docs from taget directory to a Zip
rem file in the target directory
zip -m9o "%myTargetDir%\%date%\%myZipPrefix%_%myZipSuffix%.zip" "%myTargetDir%\%date%\*.doc"
rem Move all TXT files from taget directory to a Zip
rem file in the target directory
zip -m9o "%myTargetDir%\%date%\%myZipPrefix%_%myZipSuffix%.zip" "%myTargetDir%\%date%\*.txt"
ECHO ---------
ECHO DONE!
ECHO ---------
No comments:
Post a Comment