Delete some files from backup folders

January 10, 2010 at 07:29:59
Specs: Windows XP, Athlon 64 3000+ / 3GB
Hi there,

Here my problem, I created somes batch file to perform a backup of somes data every day at work. Here a sample:

@ECHO OFF
ECHO ---------- EXECUTION DE SAUVEGARDE DE DONNEES ----------
ECHO ---------- SVP NE PAS INTERROMPE LE PROCESSUS ----------
Soon
XCOPY /Y "C:\Documents and Settings\portal_user.THS101455\Bureau\*.*" /S /D Y:\Dimanche\bureau\
XCOPY /Y "C:\Documents and Settings\portal_user.THS101455\Mes documents\*.*" /S /D Y:\Dimanche\MesDocs\
XCOPY /Y "C:\PAYCLOCK\Database\*.*" /S /D Y:\Dimanche\payclockdb\
XCOPY /Y "C:\Program Files\RDSoffice Enterprise\Data\Archive\*2009*.*" /S /D Y:\Dimanche\RDS\Archive\
XCOPY /Y "C:\Program Files\RDSoffice Enterprise\Data\Backup\*2009*.*" /S /D Y:\Dimanche\RDS\Backup\
ECHO.
ECHO ---------- EXECUTION DE SAUVEGARDE DE DONNEES ----------

My problem, how can I delete files from the backup folder who are not in the original folder anymore. For example, I got "123.xls" on my deskstop monday, the batch file will copy it monday, but the next monday the file "123.xls" is not on my deskstop anymore, but still in my backup... I would like erase this "123.xls" file from backup folder...

Thanks for your help

Best regards

Bullbee


See More: Delete some files from backup folders

Report •


#1
January 10, 2010 at 11:31:53
Simplifying the directory structure, if you back up from:

c:\files
to:
e:\bak

Then you can use the script below. It doesn't *DO* the delete; it previews what's to be done. To activate it, remove the ECHO in front of DEL.

====================
@echo off & setLocal EnableDELAYedeXpansion

:pushd e:\bak

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if not exist "c:\files\%%a" (
echo DEL "%%a"
)
)


=====================================
Helping others achieve escape felicity

M2


Report •
Related Solutions


Ask Question