Discussion Locked

Batch file needed

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need a batch file that will take two arguments 'rootdirectory' and 'junkdirectoryname'. It should search 'rootdirectory' and all its subdirectories and delete all directories named 'junkdirectoryname' on all levels. It should also error check inthe begining that both arguments were provided and 'rootdirectory' exists.

4 replies

by tchieng

Your program there can not be done easily with a batch file. Your best bet is to do it in a programming language like C or Pascal that can do recursive calls.

Look on the Internet. It probably already exists somewhere - just need to find it. Can't find one? I might be able to write you one if I have some free time.

by roman_empire

@echo off
REM ########
REM ## KillJunk.cmd by Andreas Vavra (Andreas.Vavra@brz.gv.at) (C) 2000
REM ## aka Vavi (andi@compass.co.at)
REM ##
REM ## This scripts removes all directories named %2 in %1 including all of their
REM ## subdirectories.
REM ##
REM ## USE AT YOUR OWN RISK!
REM ##
REM ########

if (%1)==() goto USAGE
if (%2)==() goto USAGE

if not exist %1 goto NOROOT

cd /D %1
for /D /R %%i in (*.*) do if (%%~ni)==(%2) rd %%i /S /Q
goto ENDE

:NOROOT
echo root-dir %1 does not exist
goto ENDE

:NOJUNK
echo junk-dir %2 does not exist
goto ENDE

:USAGE
echo USAGE killjunk.cmd "root-dir" "junk-dir-name"
goto ENDE

:ENDE

This discussion is closed to new replies.