Page 1 of 2 12 LastLast
Results 1 to 16 of 18

Thread: windows script to delete files older than 1 week

  1. #1
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,872
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    windows script to delete files older than 1 week

    I have setup a FTP for a customer on one of my games server, i am using robocopy to move the files over the network to the ftp folder once a day, i use the MOVe command to delete the source files once they hit the destination.

    he can then ftp in and grab what he wants.

    now customers are lazy and i doubt he will delete them before the folder size gets to 10's of GB's big so i am after a script i can run via the task schedule to delete anything older than 1 week.

    anyone got anything semi idiot proof for me ?

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

  2. #2
    Jay
    Jay is offline
    Gentlemen.. we're history Jay's Avatar
    Join Date
    Aug 2006
    Location
    Jita
    Posts
    8,365
    Thanks
    304
    Thanked
    568 times in 409 posts

    Re: windows script to delete files older than 1 week

    If no one replies by morning i'll knock you up a vbscript to do it.
    □ΞVΞ□

  3. Received thanks from:

    GoNz0 (21-07-2011)

  4. #3
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,872
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    Re: windows script to delete files older than 1 week

    thanks, i found one but it needed manual input each time, i just dont know anything about them to edit it to suit

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

  5. #4
    Splash
    Guest

    Re: windows script to delete files older than 1 week

    yoinked from Google because I'm lazy too

    Code:
    ‘ ################################################################
    ‘ # cleanup-folder.vbs
    ‘ #
    ‘ # Removes all files older than 1 week
    ‘ # Authored by Spencer Kuziw (s.kuziw-at-epic.ca)
    ‘ # Based on code by YellowShoe
    ‘ # Version 1.0 - Sept 23 2008
    ‘ ################################################################
     
    Dim fso, f, f1, fc, strComments, strScanDir
     
    ‘ user variables
    ‘ —————————————————————-
     
    strDir = “FULL\PATH\TO\FOLDER\TO\BE\CLEANED”
    strDays = 7
     
    ‘ DO NOT EDIT BELOW THIS LINE
    ‘ (unless you know what you are doing)
    ‘——————————————————————
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(strDir)
    Set fc = f.Files
    For Each f1 in fc
          If DateDiff("d", f1.DateCreated, Date)> strDays Then
                ‘strComments = strComments & f1.name & ” “ & f1.DateCreated & vbCrLf
                fso.DeleteFile(f1)
          End If
    Next
     
    ‘wscript.echo strComments
    WScript.Quit
    ‘ eof
    Set strDir and strDays to whatever you need, job's a good'un.

    EDIT - save file as a .vbs file.
    Last edited by Splash; 21-07-2011 at 08:41 AM.

  6. Received thanks from:

    GoNz0 (21-07-2011)

  7. #5
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,872
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    Re: windows script to delete files older than 1 week

    sweet, just what i need thanks

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

  8. #6
    Jay
    Jay is offline
    Gentlemen.. we're history Jay's Avatar
    Join Date
    Aug 2006
    Location
    Jita
    Posts
    8,365
    Thanks
    304
    Thanked
    568 times in 409 posts

    Re: windows script to delete files older than 1 week

    thats a pretty decent little script that one.
    □ΞVΞ□

  9. #7
    Splash
    Guest

    Re: windows script to delete files older than 1 week

    I should be clear - I didn't write it. As I say, I like to be lazy wherever possible so a quick Google and then run through the script does me fine. In this case I didn't even have to tweak!

  10. #8
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,872
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    Re: windows script to delete files older than 1 week

    it wont work

    just gives an error saying

    line1
    char1
    error invalid character
    code 800a0408
    ms vbscript comp error

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

  11. #9
    Technojunkie
    Join Date
    May 2004
    Location
    Up North
    Posts
    2,580
    Thanks
    239
    Thanked
    213 times in 138 posts

    Re: windows script to delete files older than 1 week

    Has that script been edited for display on a webpage at some point?
    It has HTML encoding in it.

    I'm sure those & should be &
    And the > should be >
    Chrome & Firefox addons for BBC News
    Follow me @twitter

  12. #10
    Senior Member
    Join Date
    Aug 2005
    Location
    Surrey
    Posts
    299
    Thanks
    3
    Thanked
    4 times in 4 posts

    Re: windows script to delete files older than 1 week

    You can use this in Powershell:

    Code:
    $FolderPath = "Folder path"
    $Date = get-date
    $Datetodelete = $date.adddays(-7)
    get-childitem -Path $FolderPath | where {$_.CreationTIme -le $Datetodelete} | Remove-item

  13. #11
    Member
    Join Date
    Aug 2009
    Posts
    182
    Thanks
    3
    Thanked
    23 times in 22 posts
    • barry2811's system
      • Motherboard:
      • Gigabyte GA-Z87-HD3
      • CPU:
      • Intel i5 4670K (cooled by Noctua NH-D14)
      • Memory:
      • 2 x 8GB Corsair
      • Storage:
      • Samsung Pro 128GB Boot Drive, 1 x 6TB Seagate, 1 x 3TB Seagate and 256GB Crucial SSD for games
      • Graphics card(s):
      • Asus GTX970 Strix
      • PSU:
      • EVGA SuperNova 650 G2
      • Case:
      • NZXT S340 Elite
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Viewsonic VG2439M-LED
      • Internet:
      • Sky Fibre

    Re: windows script to delete files older than 1 week

    Quote Originally Posted by mikerr View Post
    Has that script been edited for display on a webpage at some point?
    It has HTML encoding in it.

    I'm sure those & should be &
    And the > should be >
    You'd be right, but that line is commented out and is only enabled for debugging purposes by the looks of it.

  14. #12
    Member
    Join Date
    Aug 2009
    Posts
    182
    Thanks
    3
    Thanked
    23 times in 22 posts
    • barry2811's system
      • Motherboard:
      • Gigabyte GA-Z87-HD3
      • CPU:
      • Intel i5 4670K (cooled by Noctua NH-D14)
      • Memory:
      • 2 x 8GB Corsair
      • Storage:
      • Samsung Pro 128GB Boot Drive, 1 x 6TB Seagate, 1 x 3TB Seagate and 256GB Crucial SSD for games
      • Graphics card(s):
      • Asus GTX970 Strix
      • PSU:
      • EVGA SuperNova 650 G2
      • Case:
      • NZXT S340 Elite
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Viewsonic VG2439M-LED
      • Internet:
      • Sky Fibre

    Re: windows script to delete files older than 1 week

    Quote Originally Posted by GoNz0 View Post
    it wont work

    just gives an error saying

    line1
    char1
    error invalid character
    code 800a0408
    ms vbscript comp error
    Complete guess here, but try changing the ` to a '. Looks like the comment character got changed on a webpage transition somewhere?

  15. #13
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,872
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    Re: windows script to delete files older than 1 week

    Quote Originally Posted by mark19632 View Post
    You can use this in Powershell:

    Code:
    $FolderPath = "Folder path"
    $Date = get-date
    $Datetodelete = $date.adddays(-7)
    get-childitem -Path $FolderPath | where {$_.CreationTIme -le $Datetodelete} | Remove-item
    what do i do stick it in a bat file with powershell to start ?

    i am not to clever with these things

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

  16. #14
    Member
    Join Date
    Aug 2009
    Posts
    182
    Thanks
    3
    Thanked
    23 times in 22 posts
    • barry2811's system
      • Motherboard:
      • Gigabyte GA-Z87-HD3
      • CPU:
      • Intel i5 4670K (cooled by Noctua NH-D14)
      • Memory:
      • 2 x 8GB Corsair
      • Storage:
      • Samsung Pro 128GB Boot Drive, 1 x 6TB Seagate, 1 x 3TB Seagate and 256GB Crucial SSD for games
      • Graphics card(s):
      • Asus GTX970 Strix
      • PSU:
      • EVGA SuperNova 650 G2
      • Case:
      • NZXT S340 Elite
      • Operating System:
      • Windows 10
      • Monitor(s):
      • Viewsonic VG2439M-LED
      • Internet:
      • Sky Fibre

    Re: windows script to delete files older than 1 week

    Oh, and change this line;

    Code:
    If DateDiff("d", f1.DateCreated, Date)> strDays Then
    to this;

    Code:
    If DateDiff("d", f1.DateCreated, Date) > strDays Then
    Was picked up above by mikerr, but I didn't see this line when I referred to the commented line.

  17. #15
    Senior Member
    Join Date
    Aug 2005
    Location
    Surrey
    Posts
    299
    Thanks
    3
    Thanked
    4 times in 4 posts

    Re: windows script to delete files older than 1 week

    Quote Originally Posted by GoNz0 View Post
    what do i do stick it in a bat file with powershell to start ?

    i am not to clever with these things
    1) Save the powershell code in a text file with a .ps1 extention
    2) In he Batch file use call C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "path to script"

    You'll need to install powershell on your system if you haven't already, you can download it here:
    http://support.microsoft.com/kb/968930

    I use powershell for almost all my windows scripting now, much less complicated than VB

  18. Received thanks from:

    GoNz0 (22-07-2011)

  19. #16
    DILLIGAF GoNz0's Avatar
    Join Date
    Jun 2006
    Location
    Derby
    Posts
    10,872
    Thanks
    632
    Thanked
    1,192 times in 945 posts
    • GoNz0's system
      • Motherboard:
      • Asus Rampage V Extreme
      • CPU:
      • i7 something X99 based
      • Memory:
      • 16gb GSkill
      • Storage:
      • 4 SSD's + WD Red
      • Graphics card(s):
      • GTX980 Strix WC
      • PSU:
      • Enermax Galaxy 1250 (9 years and counting)
      • Case:
      • Corsair 900D
      • Operating System:
      • win10 64bit
      • Monitor(s):
      • Dell 24"
      • Internet:
      • 220mb Cable

    Re: windows script to delete files older than 1 week

    thanks, will let you know in a week if files start to vanish

    Capitalization is the difference between helping your Uncle Jack
    off a horse and helping your uncle jack off a horse.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HDD & Windows 7 issue
    By SHare in forum Help! Quick Relief From Tech Headaches
    Replies: 3
    Last Post: 29-04-2011, 01:52 PM
  2. Replies: 11
    Last Post: 14-07-2009, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •