codec
codec

Reputation: 355

Delete Folder and contents with contains specific name

I would like to delete the folder and it contents when it contains a specific string in its folder name.

For example,

C:\Documents\System_This_Computer_08-01-Mon_1416
C:\Documents\System_This_Computer_09-01-Tue_1120
C:\Documents\System_This_Computer_10-01-Wed_2315
C:\Documents\System_This_Computer_11-01-Thu_0816
C:\Documents\MyDocus
C:\Documents\ToPrintout

With the above folders, i want to delete the folder which contains strings like System_This_Computer.

So, the output should be,

C:\Documents\MyDocus
C:\Documents\ToPrintout

should only be available. remaining should be deleted.

May I know how to do this?

Upvotes: 0

Views: 1439

Answers (1)

Compo
Compo

Reputation: 38719

From my comment, the following should show you all of the directories in C:\Documents which have names beginning with System_This_Computer and have not been modified in the last 10 days.

ForFiles /P "C:\Documents" /M "System_This_Computer*" /D -10 /C "Cmd /C If @isdir==TRUE Echo @path"

Once you are satisfied with the output, change Echo to RD /S/Q to actually remove them.

Upvotes: 1

Related Questions