Batch file to delete files older than N days

前端 未结 24 2535
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 11:11

I am looking for a way to delete all files older than 7 days in a batch file. I\'ve searched around the web, and found some examples with hundreds of lines of code, and oth

24条回答
  •  自闭症患者
    2020-11-21 11:42

    Copy this code and save it as DelOldFiles.vbs.

    USAGE IN CMD : cscript //nologo DelOldFiles.vbs 15

    15 means to delete files older than 15 days in past.

      'copy from here
        Function DeleteOlderFiles(whichfolder)
           Dim fso, f, f1, fc, n, ThresholdDate
           Set fso = CreateObject("Scripting.FileSystemObject")
           Set f = fso.GetFolder(whichfolder)
           Set fc = f.Files
           Set objArgs = WScript.Arguments
           n = 0
           If objArgs.Count=0 Then
               howmuchdaysinpast = 0
           Else
               howmuchdaysinpast = -objArgs(0)
           End If
           ThresholdDate = DateAdd("d", howmuchdaysinpast, Date)   
           For Each f1 in fc
         If f1.DateLastModified

提交回复
热议问题