batch to backup today work

March 5, 2009 at 07:53:55
Specs: Windows XP, 2 gb
Hi all

I know that this problem has already been covered somewhere in this forum but I need just a little final tweaking (I hope!) to complete my task (please help me!)

My problem:
I need to backup the daily work by JUST copying the files with today timestamp (I mean the files today modified or created)

What I have done up to now (very simple indeed!)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@echo off

set dd=%date:~0,2%
set mm=%date:~3,2%
set yyyy=%date:~6,4%

set today=%mm%-%dd%-%yyyy%

xcopy *.* /y /d:%today% bkp\

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

My first attempt works fine as long as I need to backup all files resident in a single dir

Now I need to generalise the code so that it can check for “today files” in a given local dir and also all related subdirs and backup everything in a net user directory

My second attempt (not working)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@echo off
setLocal EnableDelayedExpansion

set dd=%date:~0,2%
set mm=%date:~3,2%
set yyyy=%date:~6,4%

set today=%mm%-%dd%-%yyyy%


for /d %%a in (here I want to specify a given dir) do (
xcopy %%a\*.* /s /q /y /d:%today% \\xxx\xx\yy\%%a\

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

is the problem related to the declaration of dynamic variables (!) instead of “frozen” ones (%)? Obviously, other than to the (in)correct specification of the dir to check files inside the for loop…

I’ve made many attempts but none of them were successful: sorry but really I could not catch (sort out) the problem.

Any help? Any other alternative solutions?

Thank you so much

max


See More: batch to backup today work

Report •


#1
March 5, 2009 at 08:59:15
::recursive folder example
@echo off

echo   -=EXAMPLE FOR/F LOOP WITH DIR COMBO=-
for /f %%a in ('dir/b/ad/s') do echo %%a

echo   -=EXAMPLE FOR/R LOOP (include cur dir)=-
for /r %%a in (.) do echo %%~dpnxa

echo   -=EXAMPLE FOR/D LOOP WITH PUSHD COMBO=-
call:loop
goto:eof

:loop
for /d %%a in (*) do (
	echo %%~dpna
	pushd %%a
	call:loop
	popd
)


Report •

#2
March 5, 2009 at 23:56:07
thank you reno

a very good lesson on recursive folder scanning;
by the way, as far as I understand your first example (i.e. FOR/F LOOP WITH DIR COMBO) is dealing just with current sub-folders;
but because I need to include also files in the current folder, the other two examples fit perfectly my needs;
with a little more tweaking my script works perfectly

bye

max

ps I think that is quite obvious (it is a long story that we all know very well) but the above script works perfectly just in my date layout!


Report •

Related Solutions


Ask Question