Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Source code backup batch file!

50 views
Skip to first unread message

Harry Potter

unread,
May 5, 2013, 3:11:28 PM5/5/13
to
Before I get into it I'd like to thank all of you for help in figuring out the date mechanism used in this file. :)

I just finished a batch file that's like the source code compression batch file I posted here a while ago but goes one step further. Here it is:

BackupToFloppy.BAT:
---------------------------------
@echo off
echo Hi!>"%temp%\hptemp.txt"
for %%a in ("%temp%\hptemp.txt") do set date1=%%~ta
del "%temp%\hptemp.txt"
set date2=%date1:~6,4%-%date1:~0,2%-%date1:~3,2%
echo %date2%
pause

set arcname="%~n1_%date2%.7z"
set cpa=c:%homepath%\desktop
md "%cpa%\hptemp"
md "%cpa%\hptemp\%~n1"
cd "%cpa%\hptemp\%~n1"
echo d|xcopy %1 /e
del /s /q *.prg *.obj *.map *.d64 *.exe *.o
cd..
"C:\Program Files\7-Zip\7z.exe" a %arcname% "%~n1" -r -mx=9 -m0=lzma2
if errorlevel 1 goto end
move /y %arcname% a:\
if errorlevel 1 goto end
cd..
rd /s /q "%cpa%\hptemp"

:end
pause
--------------------------
Here are some notes about this file:

* Just like the previous file, the directory on the move line should be changed to the desired backup directory, and the 7-Zip line's path may need to be adjusted.
* This file assumes you use a reasonably recent version of 7-Zip that supports LZMA2 compression. If you don't, change lzma2 to lzma.
* The file is hard-coded for the U.S. locale. If you live elsewhere, you may have to change the line that starts with set date2. I welcome locale conversions, but I write the archive date as YYYY-MM-DD for better sorting purposes.
* The cpa variable is assigned the work folder. Change if desired.

I have one question, though: how do I use local variables?

foxidrive

unread,
May 6, 2013, 1:04:35 AM5/6/13
to
On 6/05/2013 05:11, Harry Potter wrote:
> Before I get into it I'd like to thank all of you for help in figuring out the date mechanism used in this file. :)

> I have one question, though: how do I use local variables?


Do you mean using setlocal so that the variables are cleared when the batch file ends?
This style works - the endlocal is optional as it is implied when a batch file ends.


@echo off
setlocal

set var=abc
rem code goes here
echo %var%

endlocal

echo."%var%"
pause



--
foxi

Harry Potter

unread,
May 6, 2013, 10:17:06 AM5/6/13
to
On Monday, May 6, 2013 1:04:35 AM UTC-4, foxidrive wrote:
> Do you mean using setlocal so that the variables are cleared when the batch file ends? This style works - the endlocal is optional as it is implied when a batch file ends. @echo off setlocal set var=abc rem code goes here echo %var% endlocal echo."%var%" pause -- foxi

Thank you for the setlocal keyword. I have another issue, also. When I was writing this batch file, I wrote some test lines to determine that I got the date format right. When I did so, I forgot to remove the test lines. Therefore, when the file runs, it will display the date and pause. To remove this behavior, you should remove the following lines from the batch file:

echo %date2%
pause

That's all.
0 new messages