i need a command to remove all sub dirs except for the current dir name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 117
Joined: 26 Aug 2017 06:11

i need a command to remove all sub dirs except for the current dir name

#1 Post by nnnmmm » 23 Oct 2022 05:32

RMDIR /S m:\ABC

/S Removes all directories and files in the specified directory in addition to the directory itself.
addition to the directory itself. is a problem for me.

i want some command that does like RMDIR except for the addition to the directory itself part.
I need the current dir name to stay put.
when the current dir is removed by RMDIR, the windows explorer falls back to the parent directory window, this creates a constant annoying situation for running drag and drop batch files, because i need BIG FILE icons in the file window

Code: Select all

this is to delete all in the G1 directory before a new one starts. And a new one starts [b]very very often[/b] in drag and drop batch operations
set G1=M:\ABC
IF EXIST "%G1%" RMDIR /S /Q "%G1%"
MKDIR "%G1%"
i didnt find any options to make explorer go to the file window by command lines, instead every explorer options i found were to start a new one insead of using the old explorer.
Explorer /e, /select, filename
Explorer /e, /select, path

using NirCMDC.EXE in a batch can do what i want but with the price at the moment, i have to use NirCMDC.EXE wait 1000
i have to pay the prices for running NirCMD and for the WAIT option

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: i need a command to remove all sub dirs except for the current dir name

#2 Post by aGerman » 23 Oct 2022 05:52

Just iterate through the subfolders.

Code: Select all

for /d %%i in ("%G1%\*") do rd /s /q "%%i"
Steffen

nnnmmm
Posts: 117
Joined: 26 Aug 2017 06:11

Re: i need a command to remove all sub dirs except for the current dir name

#3 Post by nnnmmm » 23 Oct 2022 07:43

Code: Select all

for /d %%i in ("%G1%\*") do rd /s /q "%%i"
DEL /Q "%G1%"
thanks that did it.
i guess this means no simple command but a program

this is a proof as to how poorly i know of the DOS batch
IF EXIST "%G1%" DEL /Q "%G1%"  : this unnecessary part did me some strange wonders to buy MKDIR extra time.
IF EXIST "%G1%" RMDIR /S /Q "%G1%"
MKDIR "%G1%"

SET QQ=C:\NIRCMDC.EXE
%QQ% WIN CLOSE CLASS "CabinetWClass"
%QQ% WAIT 999
EXPLORER.EXE "%G1%" 

Post Reply