I have a script that runs the command:
del c:\mydir\*.*
Is there a command line switch I can use that will also delete all subfolders in that directory? Thanks!
I have a script that runs the command:
del c:\mydir\*.*
Is there a command line switch I can use that will also delete all subfolders in that directory? Thanks!
If there are files in the C:\mydir directory then you'll need to do both lines. Otherwise, the first line will do what you want:
That preserves the C:\mydir directory.
Edit: David1235 is quite right. If you want to do this in a batch file, you'll need to double-up the "%" in the "FOR ..." line.
It's a little unclear to me why David1235's script needs the "pushd" and "popd" when you can specify the path right in the "FOR ..." and "DEL ..." lines, though.
If you want to run your script from anywhere, try
In a batch script, you need the double percent signs. From "help for":
Is there a reason that:
DEL /Q /S C:\mydir\*
won't work?
Instead of complex FOR...LOOPS etc. I would just use:
... but an even faster method is:
as RD is "remove directory" just as the old DELTREE
Yes, rmdir.
(hint: rmdir /?)
Edit: You probably want to keep the folder. Try this out in a batch file:
The shortest and simplest way:
This preserves the parent folder, which may have ACLs that you want to keep. If any of the contents are in use, you will get errors. If you want to silence and ignore those, add a
2>nul
at the end.If you want to remain in the current directory, or have a UNC path, use PUSHD + RD + POPD instead of CD + RD.
i'm using virutal machine with ms dos 6.22. rd command can't have parameters...
to delete c:\folder\folder\folder with files and whatever if you are on c:\ use:
deltree \folder (it will ask for confirmation) deltree \y c:\folder (it will do it right away)