Solved

Need a script

Posted on 2011-09-21
9
184 Views
Last Modified: 2012-05-12
Hi,

I need a script to identify what are the folders that are 7 days old in a particular path and to delete those folders automatically. The script should look only for folders and not for files. Thanks
0
Comment
Question by:jmohan0302
  • 4
  • 3
  • 2
9 Comments
 
LVL 4

Expert Comment

by:Gavincr001
ID: 36576377
Have you looked at the Forfiles command, it can find files or folders of a certain age:

This example, removes directories older than 20 days in c:\temp.

 forfiles /p "c:\temp" /c "cmd /c if @isdir==TRUE RMDIR /S /Q @path" /d -20
0
 
LVL 4

Expert Comment

by:Gavincr001
ID: 36576385
... sorry only saw now you asking about vb
0
 

Author Comment

by:jmohan0302
ID: 36577971
Not a problem I need any thing that fulfills my work. Even a command or a script any thing
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 36578011
This should be close, adjust the constants at the top as needed.  Right now the actual delete is commented out, and it will just display the folders it thinks should be deleted.  This is for testing, if it works right uncomment out the delete.  Also, it is checking the date the folder was created currently, not last modified, since you didn't specify I wasn't sure so started with this.

Const conBaseDir = "C:\EE\Temp"
Const conDelAge = 7

' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Call recursive routine to clean out old folders
CleanFolder objFSO.GetFolder(conBaseDir), conDelAge

' Release file system object
Set objFSO = Nothing


' Recursive subroutine to remove old subfolders
Sub CleanFolder(objFolder, intAge)

   ' See if this folders subfolders are old enough to delete.
   For Each objSubFolder In objFolder.SubFolders
      If DateDiff("d", objSubFolder.DateCreated, Now) >= intAge Then
         ' objSubFolder.Delete
         Wscript.Echo "Deleted Folder: [" & objSubFolder.Path & "], Age: [" & DateDiff("d", objSubFolder.DateCreated, Now) & "]"
      Else
         CleanFolder objSubFolder, intAge
      End If
   Next

End Sub

Open in new window

~bp
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jmohan0302
ID: 36578196
Hi Billprew, Thanks for your reply. Yet I didnt check. I will check and let you know the output. I just want to know that it has to delete all the folders that is 7 days old. Thanks again
0
 

Author Comment

by:jmohan0302
ID: 36582303
Hi Gavincr001,

Please let me know from where you got these kind of commands. I just want to create these kinds of commands on own.  Any help from your end will be greatfull. Thanks
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 36584254
ForFiles is an add on utility for Windows from Microsoft.  It was released in some of the Resource Kits and now is also part of Windows 7.  Further info can be found at:

http://technet.microsoft.com/en-us/library/cc753551%28WS.10%29.aspx

http://www.petri.co.il/download_free_reskit_tools.htm

~bp
0
 

Author Comment

by:jmohan0302
ID: 36690001
Hi All,

The below forfiles command is working fine in Win7,WIn2003 and WIn2008:

forfiles /p "e:\shilpa" /c "cmd /c if @isdir==TRUE RMDIR /S /Q @path" /d -20

But it is not working in win2000.

Need help to use the forfiles command in 2000 to delete the folders in a path which is 7 days old.

Thanks
0
 
LVL 4

Accepted Solution

by:
Gavincr001 earned 500 total points
ID: 36712966
You can try copy the forfiles.exe from Win7 or server 2008 to your Win2000 PC.

Or setup the scheduled task from a Win7 PC to delete the files on a mapped drive/UNC path to the Win2000 server.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now