I'm using Windows XP. USA, MM/DD/YYYY
Main Topics
Browse All TopicsHello,
I cannot for the life of me find a vbscript or batch file to delete folders older than a week. The script needs to check the date the folder was created and if the folder is older than a week, delete it and anything inside of it.
I'm using it on folders of digital pictures, so I cannot just use a script that checks file dates/times, as the pictures may be a year or more old. It needs to just check the folder created date/time.
Is this possible? Any help is appreciated, thank you!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I need it so the top level folder doesn't get checked, but rather everything inside of it does.
I have the folders in D:\Folders and when I set it to check that directory, it's checking the timestamp on D:\Folders and not the folders inside of that directory. It's seeing D:\Folders is older than a week and wanting to remove everything inside of it.
I even tried mounting the folder as a network drive and setting the folder as Z:\. But it's wanting to remove Z:\ and not checking the folders inside.
I hope it's a quick fix for you.
After playing with this a bit and making a bunch of copies of the batch with the folder set differently in each one, I noticed I'm still going to have a problem.
Let me explain exactly what our machines are doing in the hopes you don't have to waste any more time because I wasn't clear enough in the beginning:
1) On the D: drive, there is a folder called PhotoCenterCache.
2) Inside this folder are a bunch of different folders named in this format: YYYYMMDD - example: 20090126, 20090107, etc.
3) Inside each of those folders are more folders named in this format: Import Media, Import Media_1, Import Media_2, etc.
4) The Import Media folders are the folders that have all of the photos in them. These are the folders that need to be removed if the creation time on the folder is older than a week.
5) Once all of the folders and their files have been cleared out and there's nothing left in one of the YYYYMMDD format folders, that folder can be deleted.
I realized after I was playing with this that even if you can get it working to not delete the folder I set it to check, it's going to see the creation time on the YYYYMMDD folder is possibly older than a week and want to remove everything inside of it. This scenario can only happen if the folder is actually empty. If a file is modified somewhere in a subfolder within the YYYYMMDD folder, does it update the last written/modified date for the YYYYMMDD folder? This I do not know. It might be easier to just check when it's empty and then remove it.
If you need any more clarification before proceeding, please ask. Again, I apologize for trying to generalize my situation, resulting in something that is not going to work properly.
Sample directory structure:
Volume in drive D is Local Disk
Volume Serial Number is
Directory of d:\photocentercache
01/29/2009 07:59 PM <DIR> .
01/29/2009 07:59 PM <DIR> ..
01/30/2009 07:24 PM <DIR> 20090126
0 File(s) 0 bytes
Directory of d:\photocentercache\200901
01/30/2009 07:24 PM <DIR> .
01/30/2009 07:24 PM <DIR> ..
01/26/2009 10:48 AM <DIR> Import Media
01/26/2009 10:54 AM <DIR> Import Media_1
01/27/2009 09:54 AM <DIR> Import Media_10
01/27/2009 11:00 AM <DIR> Import Media_11
01/29/2009 08:58 AM <DIR> Import Media_12
01/29/2009 08:57 AM <DIR> Import Media_13
01/29/2009 08:55 AM <DIR> Import Media_14
01/29/2009 08:55 AM <DIR> Import Media_15
01/29/2009 08:55 AM <DIR> Import Media_16
01/29/2009 08:55 AM <DIR> Import Media_17
01/29/2009 08:55 AM <DIR> Import Media_18
01/29/2009 08:54 AM <DIR> Import Media_19
01/26/2009 01:41 PM <DIR> Import Media_2
01/29/2009 08:43 AM <DIR> Import Media_20
01/29/2009 08:43 AM <DIR> Import Media_21
01/29/2009 08:43 AM <DIR> Import Media_22
01/29/2009 08:45 AM <DIR> Import Media_23
01/29/2009 11:23 AM <DIR> Import Media_24
01/29/2009 11:29 AM <DIR> Import Media_25
01/29/2009 11:31 AM <DIR> Import Media_26
01/29/2009 01:46 PM <DIR> Import Media_27
01/29/2009 03:18 PM <DIR> Import Media_28
01/29/2009 04:26 PM <DIR> Import Media_29
01/26/2009 01:12 PM <DIR> Import Media_3
01/30/2009 08:43 AM <DIR> Import Media_30
01/30/2009 09:50 AM <DIR> Import Media_31
01/30/2009 11:53 AM <DIR> Import Media_32
01/30/2009 12:29 PM <DIR> Import Media_33
01/30/2009 01:15 PM <DIR> Import Media_34
01/30/2009 02:09 PM <DIR> Import Media_35
01/30/2009 02:34 PM <DIR> Import Media_36
01/30/2009 05:38 PM <DIR> Import Media_37
01/30/2009 05:36 PM <DIR> Import Media_37.$ed
01/30/2009 05:55 PM <DIR> Import Media_38
01/30/2009 06:32 PM <DIR> Import Media_39
01/26/2009 01:57 PM <DIR> Import Media_4
01/30/2009 07:24 PM <DIR> Import Media_40
01/26/2009 02:39 PM <DIR> Import Media_5
01/26/2009 06:14 PM <DIR> Import Media_6
01/26/2009 07:51 PM <DIR> Import Media_7
01/27/2009 08:22 AM <DIR> Import Media_8
01/27/2009 08:30 AM <DIR> Import Media_9
0 File(s) 0 bytes
Directory of d:\photocentercache\200901
01/30/2009 07:24 PM <DIR> .
01/30/2009 07:24 PM <DIR> ..
01/26/2009 10:48 AM <DIR> Import Media
01/26/2009 10:54 AM <DIR> Import Media_1
01/27/2009 09:54 AM <DIR> Import Media_10
01/27/2009 11:00 AM <DIR> Import Media_11
01/29/2009 08:58 AM <DIR> Import Media_12
etc..
Directory of d:\photocentercache\200901
01/26/2009 10:48 AM <DIR> .
01/26/2009 10:48 AM <DIR> ..
01/26/2009 07:22 AM 36,331 100_0206.jpg
01/26/2009 07:22 AM 111,547 100_0209.jpg
01/26/2009 07:22 AM 132,203 100_0211.jpg
01/19/2009 06:43 PM 1,258,788 100_0213.jpg
01/19/2009 06:44 PM 1,297,067 100_0222.jpg
etc..
Hmm... It should be the subfolder. That it was checking. Basically from a command prompt if you do
dir /tc /ad "d:\photocentercache" | find "/"
You should see these folders with their creation dates
20090126
20090107
Try it again with
dir /ad "d:\photocentercache" | find "/"
This should be their modified dates.
But you want to do 1 more level down to RD folder when it was created over 7 days ago.
So the import media folders we'll use rd /q /s which will delete them without prompting. I'll put in a rd to remove 20090126 if it is not empty it will fail because we are not using the /q /s.
Business Accounts
Answer for Membership
by: AmazingTechPosted on 2009-01-30 at 12:39:23ID: 23512684
What is your date format?