Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I would like to have a script to remove
all files in dir#2 that are also present
in dir#1.
Files in dir#1 should not be removed.Very urgent,
Thanks a lot,
Xavier.

The following command would give a list of the files to be deleted:
XCOPY/u/n/l/y DIR2\*.* DIR1
Yes, it's XCOPY, but it won't copy anything (because of the /l switch). So, all we need to do is delete the files in that list. This batch file will do the task.
===== BATCH SCRIPT BEGIN =====
:: Leonardo Pignataro (secret_doom@hotmail.com)
@echo off
if "%1"=="GoTo:" GoTo:%2
%COMSPEC% /e:2048 /c %0 GoTo: start
goto eof
:start:: Set directories' full path below
SET DIR1=C:\Folder1
SET DIR2=C:\Folder2:: Temporary files table - mantain extentions !
SET T1=%TEMP%.\TEMP01.BAT
SET T2=%TEMP%.\TEMP02.BAT
SET T3=%TEMP%.\TEMP03.BATset P=%DIR2%\
if "%OS%"=="Windows_NT" set P=echo e100'SET %%1='> %T1%
for %%? in (rcx 7 w q) do echo %%?>> %T1%
type %T1% |DEBUG %T1% > nul
XCOPY/u/n/l/y/i %DIR2%\*.* %DIR1% |FIND /v " " > %T2%
:loop
copy/y %T1% %T3% > nul
type %T2%>> %T3%
FIND "SET %%1=" < %T3% > %T2%
call %T2% FILE
if "%FILE%"=="" goto endloop:: To activate script, remove 'echo.{demo}' from next line
echo.{demo}del %P%%FILE%FIND/v "SET %%1=" < %T3% > %T2%
goto loop
:endloop
for %%? in (%T1% %T2% %T3%) do del %%?
:eof
===== BATCH SCRIPT END =====Watch out for line wrapping!
That script is de-activated. When you run it, it will display the actions it would take if active. If those are the desired actions, then activate the script (read commented lines to do so).
Tell me if that's what you wanted.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

![]() |
clone floppy key disk
|
Script to copy and create...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |