Home All Groups Group Topic Archive Search About

Script for deleting folders + content in root of D:\ after # days

Author
29 Jan 2009 10:56 PM
lca1630
Hello,

I am wondering of one of you scripting wizards could help me with a cleanup
script that delete all folders older than # days in the root of d:\.

I am making backups of my live virtual servers and do not have enough room
to house more than one copy at a time.

The backups create folders that show the date and time so I have to make
sure it deletes all in that partition.

Thanks.

Author
29 Jan 2009 11:39 PM
Dirk Stegemann
Hi,

hope this one satisfies your needs...

--
Set oFSO = CreateObject("Scripting.FileSystemObject")
idays = 5
sFolder = "d:\"

For Each oFolder In oFSO.GetFolder(sFolder).Subfolders
If  DateDiff("d", oFolder.DateCreated, Now()) > idays Then
   WScript.Echo "folder """ & oFolder.Name & """will be deleted."
'  oFolder.delete
End If
Next
--

If you want it to delete the folders you have to uncomment
the oFolder.delete in line 8.

May be i have forgotten to force something. But it is late here in Germany
;-)

Dirk


Show quoteHide quote
"lca1630" <lca1***@discussions.microsoft.com> schrieb im Newsbeitrag
news:487A3B63-BABF-4F70-A10A-4B619D97EB0F@microsoft.com...
> Hello,
>
> I am wondering of one of you scripting wizards could help me with a
cleanup
> script that delete all folders older than # days in the root of d:\.
>
> I am making backups of my live virtual servers and do not have enough room
> to house more than one copy at a time.
>
> The backups create folders that show the date and time so I have to make
> sure it deletes all in that partition.
>
> Thanks.
Are all your drivers up to date? click for free checkup

Author
29 Jan 2009 11:46 PM
lca1630
Dirk,

Thank you so much. I will give it a try and let you know.

Thanks again for the quick response.

Show quoteHide quote
"Dirk Stegemann" wrote:

> Hi,
>
> hope this one satisfies your needs...
>
> --
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> idays = 5
> sFolder = "d:\"
>
> For Each oFolder In oFSO.GetFolder(sFolder).Subfolders
>  If  DateDiff("d", oFolder.DateCreated, Now()) > idays Then
>    WScript.Echo "folder """ & oFolder.Name & """will be deleted."
>  '  oFolder.delete
>  End If
> Next
> --
>
> If you want it to delete the folders you have to uncomment
> the oFolder.delete in line 8.
>
> May be i have forgotten to force something. But it is late here in Germany
> ;-)
>
> Dirk
>
>
> "lca1630" <lca1***@discussions.microsoft.com> schrieb im Newsbeitrag
> news:487A3B63-BABF-4F70-A10A-4B619D97EB0F@microsoft.com...
> > Hello,
> >
> > I am wondering of one of you scripting wizards could help me with a
> cleanup
> > script that delete all folders older than # days in the root of d:\.
> >
> > I am making backups of my live virtual servers and do not have enough room
> > to house more than one copy at a time.
> >
> > The backups create folders that show the date and time so I have to make
> > sure it deletes all in that partition.
> >
> > Thanks.
>
>
>
Author
30 Jan 2009 6:27 PM
lca1630
Hey Dirk,

I may need to refine what the script is doing how about just deleting
d:\vsbackups after 1 day. Thanks

Show quoteHide quote
"lca1630" wrote:

> Hello,
>
> I am wondering of one of you scripting wizards could help me with a cleanup
> script that delete all folders older than # days in the root of d:\.
>
> I am making backups of my live virtual servers and do not have enough room
> to house more than one copy at a time.
>
> The backups create folders that show the date and time so I have to make
> sure it deletes all in that partition.
>
> Thanks.
Author
30 Jan 2009 6:48 PM
Dirk Stegemann
Hi,

let's have a look what comes out of the magic wand ;-)

Set oFSO = CreateObject("Scripting.FileSystemObject")
idays = 1
sFolder = "d:\vsbackups"

Set oFolder = oFSO.GetFolder(sFolder)
If  DateDiff("d", oFolder.DateCreated, Now()) > idays Then
   WScript.Echo "folder """ & oFolder.Name & """will be deleted."
'   oFolder.delete
End If


Dirk

Show quoteHide quote
"lca1630" <lca1***@discussions.microsoft.com> schrieb im Newsbeitrag
news:2094D500-0F4D-49E9-9A60-458504A77791@microsoft.com...
> Hey Dirk,
>
> I may need to refine what the script is doing how about just deleting
> d:\vsbackups after 1 day. Thanks
>
> "lca1630" wrote:
>
> > Hello,
> >
> > I am wondering of one of you scripting wizards could help me with a
cleanup
> > script that delete all folders older than # days in the root of d:\.
> >
> > I am making backups of my live virtual servers and do not have enough
room
> > to house more than one copy at a time.
> >
> > The backups create folders that show the date and time so I have to make
> > sure it deletes all in that partition.
> >
> > Thanks.
Author
3 Feb 2009 12:34 AM
acray
As always: there are a hundred different ways to do the same thing. Here is a batch file I use to cleanup old temp and log files from servers.  It does recurse subdirectories, but as I didn't have a need to delete empty folders I didn't implement, if you need that functionality the vbscript may be a better fit.

Make a batch file called purge_old_files.bat and paste in the following code.  Just modify the 'list of directories to clean' section with your desired directories, one per line following the existing pattern.

Code: --------------------     @echo off
  SET tempX=dirs.tmp.txt
  IF EXIST %tempX% del %tempX%

  ::::::::::::::::::::::::::::::::::
  ::the list of directories to clean
  ::::::::::::::::::::::::::::::::::
  echo "c:\windows\system32\logfiles" >> %tempX%
  echo "D:\Program Files\Exchsrvr\server.log" >> %tempX%
  echo "D:\Program Files\Trend Micro\Security Server\PCCSRV\Log" >> %tempX%

  :: the work
  IF "%~1"=="" (GOTO ERROR) else SET DAYS=%1
  echo.
  echo Deleting the following files %DAYS% days old or older.
  echo.
  FOR /F "delims=," %%i IN (%tempX%) DO forfiles -p %%i -s -m *.* -d -%DAYS% -c "Cmd /C echo @Path & del @Path"
  GOTO CLEANUP

  :ERROR
  echo.
  echo You used the utility incorrectly.
  echo Usage: %0 DAYS
  echo All files older than DAYS days old will be deleted from the following directories (and subdirectories.)
  echo.
  FOR /F "delims=," %%i IN (%tempX%) DO echo %%i

  :CLEANUP
  IF EXIST %tempX% del %tempX%
  -------------------- -- acray ------------------------------------------------------------------------ acray's Profile: http://forums.techarena.in/members/acray.htm View this thread: http://forums.techarena.in/server-scripting/1112374.htmhttp://forums.techarena.in

Bookmark and Share

Post Thread options