Results 1 to 7 of 7

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

  1. #1
    lca1630 Guest

    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.

  2. #2
    Dirk Stegemann Guest

    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.




  3. #3
    lca1630 Guest

    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.

    >
    >
    >


  4. #4
    lca1630 Guest

    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.


  5. #5
    Dirk Stegemann Guest

    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.




  6. #6
    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%

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

Similar Threads

  1. No free space even after deleting files As Root
    By NamJam in forum Operating Systems
    Replies: 5
    Last Post: 11-01-2011, 08:44 AM
  2. Replies: 1
    Last Post: 24-08-2009, 09:47 PM
  3. Clear Content in cell without deleting formula
    By ARTHUR18 in forum Windows Software
    Replies: 3
    Last Post: 05-06-2009, 11:03 AM
  4. Deleting directory of more than 30 days
    By Mannat in forum Software Development
    Replies: 3
    Last Post: 04-02-2009, 01:50 PM
  5. Looking for a script to delete files older than 14 days
    By Michael Kapangama in forum Windows Server Help
    Replies: 3
    Last Post: 27-09-2008, 03:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,643,323,592.97184 seconds with 17 queries