Computing.Net > Forums > Disk Operating System > Script for removing files(2 dirs)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Script for removing files(2 dirs)

Reply to Message Icon

Name: Xavier
Date: July 11, 2002 at 06:01:35 Pacific
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 11, 2002 at 12:16:25 Pacific
Reply:

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.BAT

set 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


0
Reply to Message Icon

Related Posts

See More


clone floppy key disk Script to copy and create...



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Script for removing files(2 dirs)

DOS Script for use with Ghost 2k3 www.computing.net/answers/dos/dos-script-for-use-with-ghost-2k3/15489.html

Need format.com for Dos 6.2 www.computing.net/answers/dos/need-formatcom-for-dos-62/1913.html

Batch file that dir's minus prefix www.computing.net/answers/dos/batch-file-that-dirs-minus-prefix/16842.html