Microsoft KB Archive/68607

Deleting Duplicated Files Across Directories PSS ID Number: Q68607 Article last modified on 02-18-1993 PSS database name: O_MSDOS

3.20 3.30 4.01 5.00

MS-DOS

Question:

I have installed MS-DOS in my root directory and to a directory. I want to remove the files in my root that are duplicated in the directory. Is there an easy way to do this?

Response:

The following batch file (ZONK.BAT) can accomplish this task:

echo off del temp for %%a in (.) do echo del %1%%a >>temp echo exit >> temp command < temp del temp

ZONK.BAT must be called from the directory whose contents are to be retained and requires the path of the directory whose contents are to be deleted as a command line argument.

Please note that this is a “bare bones” implementation that makes virtually no attempts at error checking. A safer program (KILL.BAT) is listed at the end of this article.

Example:

ZONK C:

Called from C:, ZONK.BAT will remove all files in C: that are also listed in the C:directory.

The following program (KILL.BAT) features user help information and checks to guard against inadvertently deleting temporary files.

echo off cls if exist 69241057.032 goto DELTEMP if not exist %1goto BADDIR if not %1.==. goto OK echo KILL will delete all files in target directory which have echo filenames identical to files in the current directory. REM === Next line echoes blank line === echo  echo Syntax is KILL target dir echo Example: C:c: goto END


 * OK for %%a in (.) do echo del %1%%a >>69241057.032 echo exit >> 69241057.032 command < 69241057.032 del 69241057.032 goto END


 * BADDIR echo %1 directory does not exist goto END


 * DELTEMP echo Temporary file 69241057.032 already exists! echo This file must be deleted before KILL can proceed.


 * END

Additional reference words: 3.20 3.30 4.01 5.00

Copyright Microsoft Corporation 1993.