command line - Batch File Adding Space to Variable -
@echo off cls rem start backup title backup setlocal enabledelayedexpansion rem capture date/time(right down second) , assign variable set yy=%date:~-4% set dd=%date:~-7,2% set mm=%date:~-10,2% set newdate=%dd%%mm%%yy%_%time:~0,8% set newdate=%newdate::=% set foldername=svetlana_backup_%newdate% rem variables set drive=r: set sevenzip=%userprofile%\7z.exe set destination=r:\backup echo running backup batch file echo please plug in %drive% pause echo %foldername% mkdir %destination%\%foldername% /f "tokens=1,2 delims=," %%i in (backuplist.txt) ( set completesource=%%i set completedestination=%destination%\%foldername%\%%j echo source: "!completesource:"=!" echo destination:"!completedestination:"=!" mkdir "!completedestination:"=!" xcopy "!completesource:"=!" "!completedestination:"=!" /e /f ) rem zip folder using 7z command line utility %sevenzip% -tzip %destination%\%foldername%.zip %destination%\%foldername% rem remove unzipped backup folder rmdir /q /s %destination%\%foldername% pause exit
this backup batch file i've been using last couple of days. worked until morning. reason, when creates variable foldername
, contains space in string there none before. ends this:
svetlana_backup_22092016_ 93829
the space between dash , 93829 never there before until today reason. how remove , prevent happening again?
you can parse file-/foldername this
set foldername=%foldername: =%
this replace spaces empty string
the problem caused because test run @ time hour contained 1 digit. %time:~0,8%
output time including space, time stored this: 9:38:29
7 characters , read last 8 ones.
Comments
Post a Comment