I'm looking for a command line that I can add to a batch that I use.
Here's what I need to be able to do:
Lets say I have a directory:
C:\Users\username\Videos
With a subdirectories
C:\Users\username\Videos\test\sample
C:\Users\username\Videos\test2\sample
What command would I need to use to delete the sample folders in both subdirectories but not the test/test2 folders?
If you know of a way to use RMDIR that would be great but if not I'm open to ideas.
The command
will generate the list of folders to delete. Now, to process this list we wrap the command in a
for /f
command that will perform the directory removal command for each line in the output of the previous commandOr, to use it from command line
In both cases, the
for /f
will iterate over the output lines of thedir
command, storing the line in its replaceable parameter%a
and executing the code after thedo
clause.The default behaviour of
for
command is to tokenize the input lines splitting them using spaces and tabs as delimiters. To disable this behaviourdelims=
clause is used: with no delimiters there is only one token containing the full line.