@echo off rem Does one or more backup tasks -- or any other command line stuff you may want to use regulary. rem Is easy to set up (just change 5 lines) and YOU CAN USE THE CURRENT TIME AS PART OF A FILE NAME. rem rem Instructions in order what you shall do: rem 0) READ THOSE FEW LINES!! rem Search for CHAGE-HERE in this file to find all places you might have to change. rem IMPORTANT: Paths containing spaces usually need quotes around them. Try it out. rem 1) After BackupCommand= write what kind of action you want to have done (= which command shall be executed). rem Some examples are provided. Maybe you need to specify the whole path along with the rem command - you have to test this for yourself (eg whther spaces etc are accepted). rem 2) After firstParam= and secondParam*= insert the params, complete paths, whatever as you want. rem 3) call the file using startup.bat test so nothing will happen but you will see what the code _would_ do rem 4) Save this file (or a link to it) into start => programs => startup (Grrman: autostart) so it is rem executed each time windows starts. rem rem Version of 17:48 2006-07-04 ---- see www.SchoSchi.de for updates and to send me bug reports ---- Author: Georg Dembowski rem In case you do not have a command line ZIP / UNZIP installed, see http://www.info-zip.org/ ::make sure params are given correctly if not "%1"=="" if not "%1"=="test" echo Please call this batch without any parameters or (to do nothing but show what would happen) with paramter test && GOTO LBL_END echo. && echo Starting startup.bat at %DATE% %TIME%. && echo. && set isTest=%1 REM CHAGE-HERE If you're tired by long paths (folder sequences), just use a drive letter instead :-) REM Further advantage: For each drive letter, the last used subdir is remembered by most windows programs. REM So your last used path won't be forgotten if you use p: as pics and m: as music and v: as videos echo SUBST start ::subst f: "C:\Documents and Settings\exjobb\My Documents\texts\knowledge\computer\FAQs" ::subst v: "C:\Documents and Settings\exjobb\My Documents\My Videos\home made videos\not yet processed" ::subst s: "C:\2sm-svn-work\apache-servicemix\src\main\release\bin" echo SUBST end && echo. REM CHAGE-HERE You wanna call some files directly in many apps? Or open a lot of dirs in Explorer? Well, very difficult using the start menu, easy in a batch file :-) REM The way START is used here opens the other programs without pausing this batch. You may want START /WAIT APP.EXE so this batch waits until the program terminates. ::start "c:\Program Files\myEditor\edit.exe" "C:\My Docs\someFile.html" ::start "c:\Program Files\myBrowser\browser.exe" "C:\My Docs\someFile.html" ::start "c:\Program Files\IE\IE.exe" "C:\My Docs\someFile.html" ::start explorer C":\My Docs\" ::start explorer "C:\My Docs\Downloads\to sort" ::start explorer "C:\My Docs\work\task32\to do\urgent" REM CHAGE-HERE this is an example...adapt it to your needs. :: set BackupCommand=c:\some path\program.exe parameter1 /and:parameter2 :: set BackupCommand=xcopy /s /c /d /e /h /i /r /k /y :: set BackupCommand=copy :: set BackupCommand=move :: set BackupCommand=ftp -s:c:\myFTPscript.txt www.example.org :: set BackupCommand=zip -9 -r -q set BackupCommand=echo __I could be a ZIP program__ REM IMPORTANT: Paths containing spaces usually need quotes around them. Applies to secondParamFront and secondParamEnd as well. Try it out. set firstParam=C:\NoSpacesInsideSoNoQuotes\importantDir REM IMPORTANT: You may not to end secondParamFront or start secondParamEnd with an \ or space as this may produce errors, depending on your commands. set secondParamFront="Z:\My Backup is a dir with spaces\importantDir set secondParamEnd=.zip" :: withdatewill produce "secondParamFront Date Time secondParamEnd" whereas everything else produces "secondParamFrontsecondParamEnd" :: swap1stAnd2nd will swap the firstParam and 2nd arguments (important for commands that expect the destination[including date] as first parameter) call :LBL_DO_BACKUP withdate ::one more example set BackupCommand=ping -n 1 www.I_will_not_work_--_see_the_warning?...#%%)....example.org set firstParam= set secondParamFront= set secondParamEnd= call :LBL_DO_BACKUP ::one more example :: set BackupCommand=zip -9 -r -q :: set firstParam="C:\Documents and Settings\exjobb\Desktop\ThesisGeorg" :: set secondParamFront="C:\Documents and Settings\exjobb\Desktop\Backup\ThesisGeorg :: set secondParamEnd=.zip" :: call :LBL_DO_BACKUP withdate swap1stAnd2nd rem CHAGE-HERE if you want more back up tasks, uncomment and complete :: set BackupCommand=copy :: set firstParam= :: set secondParamFront= :: set secondParamEnd= :: call :LBL_DO_BACKUP withdate swap1stAnd2nd ::comes after all backups are done goto LBL_END :LBL_DO_BACKUP echo DO_BACKUP was called ::defaul: no time information in secondParamComplete. In case there shall be time information, overwrite the varibale value set myTime= if "%1"=="withdate" GOTO :LBL_TIME if "%2"=="withdate" GOTO :LBL_TIME :LBL_DO_BACKUP_CONTINUE_AFTER_TIME if "%myTime%"=="!!TIME_ERROR!!" echo. && echo. && echo ############ WARNING: THERE WAS A TIME ERROR!! ############# && echo. && echo CTRL+C breaks the bat file, so no further commands will be executed && pause ::build secondParamComplete and maybe swap set secondParamComplete=%secondParamFront%%myTime%%secondParamEnd% if "%1"=="swap1stAnd2nd" GOTO :LBL_SWAP if "%2"=="swap1stAnd2nd" GOTO :LBL_SWAP :LBL_DO_BACKUP_CONTINUE_AFTER_SWAP :: give user feedback echo Using command : %BackupCommand% echo 1.Parameter/Dir/File: %firstParam% echo 2.Parameter/Dir/File: %secondParamComplete% ::main action is here. First things will be done only if in testing mode and skipping the real action by a GOTO jump. ::echo isTest is: %isTest% if "%isTest%"=="test" echo TESTING MODE. This command line would be executed: && echo. if "%isTest%"=="test" echo %BackupCommand% %firstParam% %secondParamComplete% && echo. if "%isTest%"=="test" GOTO LBL_DO_BACKUP_CONTINUE_AFTER_ACTION ::Here is the real thing. In case something goes wrong, the user will be informed. :: this is only to clear the last error level VER | find " " >nul %BackupCommand% %firstParam% %secondParamComplete% set localErrorlevel=%errorlevel% set Warn=!WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! !WARNING! set errorText= Errorlevel was not 0, which indicates there was an error! Errorlevel was %localErrorlevel% ::if not errorlevel 0 echo errorlevel not 0 but %errorlevel% if not "%localErrorlevel%"=="0" echo %Warn% && echo %errorText% && echo %Warn% set localErrorlevel= :LBL_DO_BACKUP_CONTINUE_AFTER_ACTION echo. ::end of LBL_DO_BACKUP so return to where it was called goto :EOF :LBL_TIME :: as %TIME% is written using : as separators (eg 16:59:49,87) and those are not allowed within file names, replace : by - :: just to be sure that user sees in case anything goes wrong with the date set myTime=!!TIME_ERROR!! ::for testing use the following line at command prompt - IMPORTANT %i is for command line, %%i for use in batch files!! ::FOR /F "tokens=1,2,* delims=:," %i in ('echo %TIME%') do @echo %time% zerlegt ist %i %j %k FOR /F "tokens=1,2,* delims=:," %%i in ('echo %TIME%') do set myTime=%%i-%%j-%%k if not errorlevel 0 GOTO LBL_DO_BACKUP_CONTINUE_AFTER_TIME FOR /F "tokens=1 delims= " %%i in ('echo %myTime%') do set myTime=%%i if not errorlevel 0 GOTO LBL_DO_BACKUP_CONTINUE_AFTER_TIME set myTime=%DATE%_%myTime% GOTO LBL_DO_BACKUP_CONTINUE_AFTER_TIME :LBL_SWAP ::swap first and second argument echo Swapping 1st and 2nd parameter now... set myTemp=%firstParam% set firstParam=%secondParamComplete% set secondParamComplete=%myTemp% set myTemp= GOTO LBL_DO_BACKUP_CONTINUE_AFTER_SWAP :LBL_END echo. echo I'm done. Exiting at %DATE% %TIME%. REM CHAGE-HERE In in case you do not want the window to disappear but wait for a key stroke, uncomment the following line ::pause