Question

VBScript or batch file to delete folders older than a week

Asked by: Xerxes321

Hello,

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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-30 at 11:02:37ID24099467
Tags

Microsoft Windows

,

delete old folders

Topics

Automation

,

Windows Batch Scripting

Participating Experts
1
Points
500
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Opening up a batch file using vbscript
    Hello again, Yet another vbscript question: - I have a vbscript file which prompts the user to enter a location (eg. C:\Folder1\) into an inputbox. The location they enter is then added to a batch file. After the location is added to the batch file I'd like the script to au...
  2. Run a VBscript file from a batch file
    I need a syntax to run a VBScript file(.vbs) from a batch file(.bat) thanks
  3. Batch File
    Hi... I'm trying to create a batch file that is supposed to check a directory for specific file extensions and then delete them or move them to a different folder. After that it is supposed to send a message to the administrator or send an email to the administrator. Is t...
  4. Call a batch file in VBSCRIPT
    Call a batch file in VBSCRIPT. The batch file is located on a server and I will be inserting it into all users logon script. The script is pushed out by GPOs so it has rights to connect to the server.
  5. Execute all batch files in a folder with vbscript
    I would simply like to write a vbscript file that executes all batch files within a folder.
  6. Batch to VBScript for Logon
    I am interested in using vbscript for my logon script in my domain instead of batch. Currently, I have four sites and in my current batch file logon script, there is a " CALL %LOGONSERVER%.bat" command in the script which will map drives specific to that location fo...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: AmazingTechPosted on 2009-01-30 at 12:39:23ID: 23512684

What is your date format?

 

by: Xerxes321Posted on 2009-01-30 at 12:44:28ID: 23512749

I'm using Windows XP. USA, MM/DD/YYYY

 

by: AmazingTechPosted on 2009-01-30 at 12:46:31ID: 23512773

Actually XP USA is

M/d/yyyy

reg query "HKCU\Control Panel\International" /v sShortDate

When the shortdate is set to MM/dd/yyyy the day of the week does not show up when you do a

echo %date%

 

by: Xerxes321Posted on 2009-01-30 at 12:52:45ID: 23512833

Sorry, I was just going by what I say when using 'dir' in the command prompt.

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\Control Panel\International
    sShortDate  REG_SZ  M/d/yyyy

 

by: AmazingTechPosted on 2009-01-30 at 13:00:34ID: 23512918

No problem. I really only needed to know month day year in this case.

Removing subfolders too right? RD /q /s will remove everything.

Change the folder
Set Folder=C:\AT

When everything looks OK. Remove the ECHO from this line
ECHO RD /q /s "%Folder%\%%e"

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Set Folder=C:\AT
 
call :SubDays 7
 
for /f "tokens=1,2,3,6,* delims=/ " %%a in ('dir /tc /ad "%Folder%" ^| find "/"') do (
    if %%c%%a%%b LSS %Year%%Month:~-2%%Day:~-2% (
        ECHO Removing folder "%Folder%\%%e" creation date was %%a/%%b/%%c
        ECHO RD /q /s "%Folder%\%%e"
    )
)
 
goto :EOF
 
:SubDays
Set DaysInMonth=31,28,31,30,31,30,31,31,30,31,30,31
 
Set Year=%date:~-4%
Set Day=1%date:~-7,2%
Set Month=1%date:~-10,2%
 
Set /a Day-=%1
:FixDay
If !Day! LEQ 100 (
    Set /a Month-=1
    if !Month! == 100 (
        Set /a Year-=1
        Set Month=112
    )
    Set MCounter=101
    Set DaysInThisMonth=
 
    for %%d in (%DaysInMonth%) do if not defined DaysInThisMonth if !MCounter! == !Month! (Set DaysInThisMonth=%%d) else (Set /a MCounter+=1)
 
    if !Month! == 102 (
        if %Year:~-2% == 00 (
            Set /a Mod=!Year:~0,2! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        ) else (
            Set /a Mod=!Year! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        )
    )
    Set /a Day+=!DaysInThisMonth!
)
If !Day! LEQ 100 GOTO FixDay
GOTO :EOF
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:

Select allOpen in new window

 

by: AmazingTechPosted on 2009-01-30 at 13:01:25ID: 23512926

If you want to go older than x days modify this line

call :SubDays x

 

by: Xerxes321Posted on 2009-01-30 at 13:47:27ID: 23513349

Can it remove any system or hidden files too? We sometimes copy the entire DCIM folder off of the memory card and sometimes it includes hidden preview/thumbnail pictures that haven't played nice with other scripts we've used.

 

by: AmazingTechPosted on 2009-01-30 at 15:51:53ID: 23514215

The RD /q /s should remove all hidden and system files.

This folder is not hidden or a system is it?

 

by: Xerxes321Posted on 2009-01-30 at 17:28:44ID: 23514743

The top level folder is not, no. Some of them may be in sub directories. Does that make a difference?

 

by: AmazingTechPosted on 2009-01-30 at 21:26:41ID: 23515473

No the sub directories and files can be hidden system or read only. The top level folder should disappear.

 

by: Xerxes321Posted on 2009-01-31 at 05:36:37ID: 23516710

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.

 

by: Xerxes321Posted on 2009-01-31 at 06:00:33ID: 23516771

Tried everything I could think of to get this to work as is, but it's always checking the timestamp on the folder I set it to, rather than the folders inside of that folder.

 

by: Xerxes321Posted on 2009-01-31 at 06:37:29ID: 23516903

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\20090126

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\20090107

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\20090126\Import Media

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..

 

by: AmazingTechPosted on 2009-01-31 at 13:57:48ID: 23518748

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.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Set Folder=C:\AT
 
call :SubDays 7
 
for /f "tokens=*" %%p in ('dir /ad /b "%Folder%"') do ( 
  for /f "tokens=1,2,3,6,* delims=/ " %%a in ('dir /tc /ad "%Folder%\%%p" ^| find "/"') do (
    if %%c%%a%%b LSS %Year%%Month:~-2%%Day:~-2% (
        ECHO Removing folder "%Folder%\%%p\%%e" creation date was %%a/%%b/%%c
        ECHO RD /q /s "%Folder%\%%p\%%e"
    )
  )
  ECHO RD "%Folder%\%%p"
)
 
goto :EOF
 
:SubDays
Set DaysInMonth=31,28,31,30,31,30,31,31,30,31,30,31
 
Set Year=%date:~-4%
Set Day=1%date:~-7,2%
Set Month=1%date:~-10,2%
 
Set /a Day-=%1
:FixDay
If !Day! LEQ 100 (
    Set /a Month-=1
    if !Month! == 100 (
        Set /a Year-=1
        Set Month=112
    )
    Set MCounter=101
    Set DaysInThisMonth=
 
    for %%d in (%DaysInMonth%) do if not defined DaysInThisMonth if !MCounter! == !Month! (Set DaysInThisMonth=%%d) else (Set /a MCounter+=1)
 
    if !Month! == 102 (
        if %Year:~-2% == 00 (
            Set /a Mod=!Year:~0,2! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        ) else (
            Set /a Mod=!Year! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        )
    )
    Set /a Day+=!DaysInThisMonth!
)
If !Day! LEQ 100 GOTO FixDay
GOTO :EOF

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:

Select allOpen in new window

 

by: Xerxes321Posted on 2009-02-01 at 05:48:04ID: 23521268

I think it's getting confused. See attached output.

U:\>dir /tc /ad | find "/"
05/04/2008  12:28 PM    <DIR>          .
05/04/2008  12:28 PM    <DIR>          ..
01/26/2009  10:41 AM    <DIR>          20090126
 
U:\>dir /ad | find "/"
01/29/2009  07:59 PM    <DIR>          .
01/29/2009  07:59 PM    <DIR>          ..
01/31/2009  07:32 PM    <DIR>          20090126

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: AmazingTechPosted on 2009-02-01 at 21:14:40ID: 23524503

Oh.... I see now. Need to make sure it ignores

05/04/2008  12:28 PM    <DIR>          .
05/04/2008  12:28 PM    <DIR>          ..

These are over 1 week ago.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Set Folder=C:\AT
 
call :SubDays 7
 
for /f "tokens=*" %%p in ('dir /ad /b "%Folder%"') do ( 
  for /f "tokens=1,2,3,6,* delims=/ " %%a in ('dir /tc /ad "%Folder%\%%p" ^| find "/"') do (
    if "%%e" neq "." if "%%e" neq ".." if %%c%%a%%b LSS %Year%%Month:~-2%%Day:~-2% (
        ECHO Removing folder "%Folder%\%%p\%%e" creation date was %%a/%%b/%%c
        ECHO RD /q /s "%Folder%\%%p\%%e"
    )
  )
  ECHO RD "%Folder%\%%p"
)
 
goto :EOF
 
:SubDays
Set DaysInMonth=31,28,31,30,31,30,31,31,30,31,30,31
 
Set Year=%date:~-4%
Set Day=1%date:~-7,2%
Set Month=1%date:~-10,2%
 
Set /a Day-=%1
:FixDay
If !Day! LEQ 100 (
    Set /a Month-=1
    if !Month! == 100 (
        Set /a Year-=1
        Set Month=112
    )
    Set MCounter=101
    Set DaysInThisMonth=
 
    for %%d in (%DaysInMonth%) do if not defined DaysInThisMonth if !MCounter! == !Month! (Set DaysInThisMonth=%%d) else (Set /a MCounter+=1)
 
    if !Month! == 102 (
        if %Year:~-2% == 00 (
            Set /a Mod=!Year:~0,2! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        ) else (
            Set /a Mod=!Year! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        )
    )
    Set /a Day+=!DaysInThisMonth!
)
If !Day! LEQ 100 GOTO FixDay
GOTO :EOF
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:

Select allOpen in new window

 

by: Xerxes321Posted on 2009-02-03 at 17:34:03ID: 23544242

I am waiting a few days to post if it works or not. The folders were manually cleaned up last week, so waiting until some are older than a week to verify everything will work correctly.

I will post back with results by next Tuesday.

 

by: AmazingTechPosted on 2009-02-03 at 23:01:47ID: 23545531

Sure. Not a problem.

 

by: Xerxes321Posted on 2009-02-10 at 16:15:23ID: 23607083

Seems to be working great.

To have it check 2 folders would I just change it to the below? I'll accept as soon as I hear back from you.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
Set Folder=D:\PhotoCenterCache
Set Folder2=C:\Documents and Settings\Administrator\My Documents\My Pictures
 
call :SubDays 7
 
for /f "tokens=*" %%p in ('dir /ad /b "%Folder%"') do ( 
  for /f "tokens=1,2,3,6,* delims=/ " %%a in ('dir /tc /ad "%Folder%\%%p" ^| find "/"') do (
    if "%%e" neq "." if "%%e" neq ".." if %%c%%a%%b LSS %Year%%Month:~-2%%Day:~-2% (
        ECHO Removing folder "%Folder%\%%p\%%e" creation date was %%a/%%b/%%c
        RD /q /s "%Folder%\%%p\%%e"
    )
  )
  RD "%Folder%\%%p"
)
 
for /f "tokens=*" %%p in ('dir /ad /b "%Folder2%"') do ( 
  for /f "tokens=1,2,3,6,* delims=/ " %%a in ('dir /tc /ad "%Folder2%\%%p" ^| find "/"') do (
    if "%%e" neq "." if "%%e" neq ".." if %%c%%a%%b LSS %Year%%Month:~-2%%Day:~-2% (
        ECHO Removing folder "%Folder2%\%%p\%%e" creation date was %%a/%%b/%%c
        RD /q /s "%Folder2%\%%p\%%e"
    )
  )
  RD "%Folder2%\%%p"
)
 
goto :EOF
 
:SubDays
Set DaysInMonth=31,28,31,30,31,30,31,31,30,31,30,31
 
Set Year=%date:~-4%
Set Day=1%date:~-7,2%
Set Month=1%date:~-10,2%
 
Set /a Day-=%1
:FixDay
If !Day! LEQ 100 (
    Set /a Month-=1
    if !Month! == 100 (
        Set /a Year-=1
        Set Month=112
    )
    Set MCounter=101
    Set DaysInThisMonth=
 
    for %%d in (%DaysInMonth%) do if not defined DaysInThisMonth if !MCounter! == !Month! (Set 
 
DaysInThisMonth=%%d) else (Set /a MCounter+=1)
 
    if !Month! == 102 (
        if %Year:~-2% == 00 (
            Set /a Mod=!Year:~0,2! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        ) else (
            Set /a Mod=!Year! %% 4
            if !Mod! == 0 Set /a DaysInThisMonth+=1
        )
    )
    Set /a Day+=!DaysInThisMonth!
)
If !Day! LEQ 100 GOTO FixDay
GOTO :EOF

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:

Select allOpen in new window

 

by: Xerxes321Posted on 2009-02-21 at 10:19:45ID: 31541078

Thanks. I'll have to try and see if my mod works to check two folders.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...