Link to home
Start Free TrialLog in
Avatar of Ezra Shiram
Ezra ShiramFlag for United States of America

asked on

Delete Folders Based on Folder Name - Windows Server 2008 R2

Hello,
We have a windows server 2008 server. We have a share with a lot of folders. The subfolders inside these folders are labeled by date (ex 1-1-2015). Is there a way to run a script that will delete the folders based on their date? I know Windows sees is as a text name and not date. So, to me it sounds very complex. But please let me know how I can do this if possible. If not, is there a way to delete the subfolders (and its contents) by creation date?

Thank You!

EzraS
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ezra Shiram

ASKER

Hi David,
Thanks for the response. I ran the script (I changed the path to search and olddays to my needs). But when I ran it, it said "Delete.vbs(1, 1) Microsoft VBScript compilation error: Expected statement". What does this mean? I really don't know anything about scripting. My knowledge of scripting is as far as mapping network drives via login scripts.

Thanks!
Also, I tried running two scripts (one to delete by folders and the second by files. The one by folders did not work for me, which is "forfiles -p "C:\Users\guest\Downloads" -d -60 -c "cmd /c IF @isdir == TRUE rd /S /Q @path"". However, when running the one to delete by files "forfiles /p "C:\Users\guest\Downloads" /s /d -60 /c "cmd /c del /s /q @file"", it does work. As it runs it will delete the files and leave the folders empty.

It doesn't really matter which scripting method I use as long as it works.

Thanks Again!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial