Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-01-2009
lca1630
 
Posts: n/a
Script for deleting folders + content in root of D:\ after # days

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.

Reply With Quote
  #2  
Old 30-01-2009
Dirk Stegemann
 
Posts: n/a
Re: Script for deleting folders + content in root of D:\ after # days

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" <lca1630@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.



Reply With Quote
  #3  
Old 30-01-2009
lca1630
 
Posts: n/a
Re: Script for deleting folders + content in root of D:\ after # d

Dirk,

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

Thanks again for the quick response.

"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" <lca1630@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.

>
>
>

Reply With Quote
  #4  
Old 30-01-2009
lca1630
 
Posts: n/a
RE: Script for deleting folders + content in root of D:\ after # days

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.

Reply With Quote
  #5  
Old 31-01-2009
Dirk Stegemann
 
Posts: n/a
Re: Script for deleting folders + content in root of D:\ after # days

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

"lca1630" <lca1630@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.



Reply With Quote
  #6  
Old 03-02-2009
Member
 
Join Date: Feb 2009
Posts: 8
Re: Script for deleting folders + content in root of D:\ after # days

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%
Reply With Quote
  #7  
Old 28-03-2012
Member
 
Join Date: Mar 2012
Posts: 1
Re: Script for deleting folders + content in root of D:\ after # days

Dirk,

Thank you for sharing. I have a similar use for this script. I modified the days and directory to search to suite my needs and it works great! What I need now is for the script to auto answer "yes" when propted if I want to delete the folder. Can you or anyone help, please?
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Script for deleting folders + content in root of D:\ after # days"
Thread Thread Starter Forum Replies Last Post
No free space even after deleting files As Root NamJam Operating Systems 5 11-01-2011 08:44 AM
How can you prevent deleting folders but allow deleting files a.dorst Operating Systems 1 24-08-2009 09:47 PM
Clear Content in cell without deleting formula ARTHUR18 Windows Software 3 05-06-2009 11:03 AM
Deleting directory of more than 30 days Mannat Software Development 3 04-02-2009 01:50 PM
Looking for a script to delete files older than 14 days Michael Kapangama Windows Server Help 3 27-09-2008 03:56 PM


All times are GMT +5.5. The time now is 11:55 AM.