Deleting a directory (sub-directpries)using batch program on a event of new directory creation
I'm having trouble accomplishing the below.
I would like have a batch file th开发者_开发知识库at will delete sub directories and the files contained in them, but it should keep the latest 3 sub directories. example- c:\test\ contained in this directory are sub directories named jan012004, jan022004 and jan102004.
In the event of a new dir being added to c:test\ ie - jan112004, jan012004 should be deleted by the batch program. However if no new sub directory is added ie jan112004 the oldest sub directory should not be deleted by the batch program ie jan012004.
Thanks very you much...In advance.
Read HELP FOR
and HELP DIR
first
Then try
for /f "skip=3" %%a in ('dir /b /o-d /ad *.*') do echo %%a
this particular command will echo all subdirectories except the oldest three. You may want to change the /o-d
and /ad
parameters to better match your requirements. And change echo
to an appropiate action.
精彩评论