Results 1 to 4 of 4

Thread: Looking for a script to delete files older than 14 days

  1. #1
    Michael Kapangama Guest

    Looking for a script to delete files older than 14 days

    Please help I am looking for a vb/batch file that can delete files older
    than xx days. Also the script should have a output so that l may Blat the
    report.

    Thx.


  2. #2
    Pegasus \(MVP\) Guest

    Re: Looking for a script to delete files older than 14 days


    "Michael Kapangama" <MKAPANGAMA@SBCGLOBAL.NET> wrote in message
    news:C415AAD5.382%MKAPANGAMA@SBCGLOBAL.NET...
    > Please help I am looking for a vb/batch file that can delete files older
    > than xx days. Also the script should have a output so that l may Blat the
    > report.
    >
    > Thx.
    >


    The downloadable command xxcopy.exe has this facility already
    built into it: xxcopy /rs /db#xx /ed /yy .. . .



  3. #3
    Shay Levi Guest

    Re: Looking for a script to delete files older than 14 days



    If Windows PowerShell is an option:


    $oldFiles = (get-date).addDays(-14)
    dir <path> -recurse | where-object {-not $_.PSIsContainer -and ($_.lastWriteTime
    -ge $oldFiles)} | remove-item -force -whatIf


    Here's a breakdown of the command:

    1. $oldFiles = (get-date).addDays(-14)
    Create a date object and set it to today -14 days

    2. dir <path> *.* -recurse
    -recurse: Deletes the items in the specified locations and in all child
    items of the locations.

    3. where {-not $_.PSIsContainer -and $_.lastWriteTime -ge $oldFiles}
    You pipe the dir command to the where-object cmdlet
    -not $_.PSIsContainer: don't include directory objects
    -and $_.lastWriteTime -ge $oldFiles: where each file's lastWriteTime property
    is greater to or equel to 14 days

    4. pipe the where clause to the remove-item cmdlet:
    -force: Overrides restrictions that prevent the command from succeeding,
    it also removes read only files
    -whatIf: Describes what would happen if you executed the command without
    actually executing the command.

    When you're ready to go you can omit the -whatIf parameter




    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com

    > Please help I am looking for a vb/batch file that can delete files
    > older than xx days. Also the script should have a output so that l may
    > Blat the report.
    >
    > Thx.
    >




  4. #4
    Join Date
    Sep 2008
    Posts
    2
    You can use forfiles.exe (native on server 2003 or downloadable from the server 2000 resource kit). There is a guide here:

    http://www.jjclements.co.uk/index.ph...number-of-days
    Last edited by Sarah Lou; 27-09-2008 at 04:00 PM.

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2010, 04:14 PM
  2. delete files older than...
    By Hugo in forum Windows Server Help
    Replies: 5
    Last Post: 21-05-2010, 03:18 PM
  3. rm files older than two days
    By Adonis in forum Windows Software
    Replies: 3
    Last Post: 23-06-2009, 07:15 PM
  4. Delete files with logoff/on script
    By Pine Le in forum Windows Security
    Replies: 1
    Last Post: 03-06-2008, 11:19 PM
  5. Need a script to delete temporary ASP.NET files
    By Mak66 in forum Windows Server Help
    Replies: 2
    Last Post: 13-02-2008, 07:00 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,714,137,473.22517 seconds with 17 queries