Отвечено Need script to delete files

  • 2012년 4월 13일 금요일 오후 3:44
     
     

    Hi,

    I am needing a script that will delete files off a file share, 30 days from the "creation" date. Does anyone have a script like this?

    Thanks!

모든 응답

  • 2012년 4월 13일 금요일 오후 3:47
     
     답변됨
    There are many scripts in VB Script and Powershell in the Repository that will do this.  Just click on the link at the top of this page.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

  • 2012년 4월 13일 금요일 오후 3:56
     
     

    I took a look in there and didn't see one that says delete from creation date. I found the modified date. Am I missing it somewhere?

  • 2012년 4월 13일 금요일 오후 4:11
     
     
    What scripting language are you using? 

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

  • 2012년 4월 13일 금요일 오후 4:46
     
     

    I took a look in there and didn't see one that says delete from creation date. I found the modified date. Am I missing it somewhere?

    Just change the name of the date.

    This is a scripting forum for people who are trying to learn or are actively using scripting.  We can answer questions but not provide scripts to order.  If you don't find what you want and do not know how to edit the file then you can post a request in the repository and maybe someone will write you a script.

    You could have at least have posted the scritp with the midified date as this will be different depending on the language.


    ¯\_(ツ)_/¯

  • 2012년 4월 20일 금요일 오후 8:39
     
     

    So I found this script and it seems to work, deletes files from the root of the directory but its not deleting files in the sub folders. Can anyone help with this?

    Also, I wasn't asking someone to write a specific script for me, had asked if anyone had an already made script. I apologize if it came across that way.

    Here is the script that I have so far.

    On Error Resume Next
     
    'The following variabe contains number of days. Default is 30.
    intOlderThan = 30
     
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
     
    'The following array contains path to folder(s) which contain IIS log files. 
    'You can enter multiple folders.
    arrFolders = Array("D:\folder\*.*")
     
    For Each strPath in arrFolders
        Set objFolder = objFSO.GetFolder(Chr34&strPath&Chr34)
        Set colFiles = objFolder.Files
        For Each objFile In colFiles
            dateCreated = objFile.DateCreated
            intDaysOld = DateDiff("d", dateCreated, Now)
            If intDaysOld > intOlderThan Then
                objFile.Delete
            End If
        Next
        ErrorCheck ()
    Next
     
     
    'Function for error checking.
    Function ErrorCheck()
        If Err.Number <> 0 Then
            WshShell.LogEvent 1, "Script encountered error. Error number: " & Err.Number & _
                ". Error description: " & Err.Description
            WScript.Quit
        Else
            WshShell.LogEvent 4, "Script completed successfully."        
        End If
    End Function




    • 편집됨 Adam_Lowe 2012년 4월 20일 금요일 오후 8:39
    • 편집됨 Adam_Lowe 2012년 4월 20일 금요일 오후 8:43
    • 편집됨 Adam_Lowe 2012년 4월 20일 금요일 오후 8:43
    •  
  • 2012년 4월 20일 금요일 오후 8:40
     
     
    This is a VBscript.
  • 2012년 4월 20일 금요일 오후 9:12
     
     

    You have to recurse the subfolders.  This script just deletes one level.


    ¯\_(ツ)_/¯

  • 2012년 4월 20일 금요일 오후 9:14
     
     
    Can you tell me how to do that? I am not very good with scripts.
  • 2012년 4월 20일 금요일 오후 9:19
     
     
  • 2012년 4월 20일 금요일 오후 9:20
     
     
    Can you tell me how to do that? I am not very good with scripts.

    Look in the repository on the links I gave you.  There are hundreds of scripts to delete files older than n-days.


    ¯\_(ツ)_/¯

  • 2012년 4월 20일 금요일 오후 9:25
     
     

    So I found this script and it seems to work, deletes files from the root of the directory but its not deleting files in the sub folders. Can anyone help with this?

    Here is a recursive version of your script. I leave it to you to put the error checking routine back in again.

    intOlderThan = 30
     
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
     
    sFolder = "D:\folder"
    Set oFolder = oFSO.GetFolder(sFolder)
    Process oFolder
     
    Sub Process(oFldr)
        For Each oFile In oFldr.files
            dateCreated = oFile.DateCreated
            intDaysOld = DateDiff("d", dateCreated, Now)
            If intDaysOld > intOlderThan Then WScript.Echo "oFile.Delete", oFile.path
        Next
        
        For Each oSubFldr In oFldr.subfolders
            Process oSubFldr
        Next
    End Sub