|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Script for deleting folders + content in root of D:\ after # daysHello,
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. Hi,
hope this one satisfies your needs... -- Show quoteHide quoteSet 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. 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. > > > 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. 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. 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% :::::::::::::::::::::::::::::::::: echo "c:\windows\system32\logfiles" >> %tempX%::the list of directories to clean :::::::::::::::::::::::::::::::::: 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=%1echo. 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 You used the utility incorrectly.echo. 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
Batch Script to parse lines in text file
Command line parameters? Get attributes of user list from AD Continued xcopy script WMI Script, access denied? run once script Monitor redundent processes running on the Windows Server send mail if ping faile Batch file to delete files dynamically Bulldog (Need help with script downloaded from script center) |
|||||||||||||||||||||||