vbscript - I would like to delete 7 days older, files. folders and empty folders -


After

I want to delete 7 days old, delete files and empty folders. I have used the script below from the link, but since the souce is pointing directly to the letter drive, some files and folders are not being removed. However, if we change the source folder then c: \ temp \ lab everything works fine.

  const active = true const sSource = "E:" Const MaxAge = 7 'day const Recursive = True checked = 0 deleted = 0 set OFSO = CreateObject ("Scripting.FileSystemObject") if Active "action" = "delete" "other verb =" old file: "" "checkfolder osso. Gatefolder (ssro) WScript.echo if activated then action =" file has been deleted "other action =" file (s) Removed "WScript.Echo checked" & checked file (s), & amp; deleted & verb sub checkfolder (offender) each off Checked in oFldr.Files = Checked + 1 if Detoff ("D", Opile. DataList, now ())> MaxAge then deleted deleted + 1 WScript.Echo Action & amp; Opfile. Path & amp; "" If enabled, then open the file. Stop repeating if it is not recursive next, then exit for each oSubfolder CheckFolder (oSubfolder) Next End in oFldr.Subfolders. Sub    

itemprop = "text">

Well, about what it is:

  const active = True Constance sSource = "e: \ start_folder" or "E: \" but not "E:" Const MaxAge = 7 'Dest Recursive = true Dim dtOld, checked, deleted, verb DTOld = now - MaxAge checked If = 0 is deleted = 0 is activated then action = "deleting" "other verb =" old file: "" "valid sSource cleaning sSource WScript.Echo then active then verb = action =" file (files) Will be deleted "WScript.Echo checked and deleted" file (s) "; "Checked the file (s)," & amp; Deleted & amp; CreateObject ("Scripting.FileSystemObject") with the verb sub object (sfolder) if not. Foller accelerates (sFolder) then error Rhiz 76 'path is not found if ghetfolder (sFolder). ITSRootFolder then if .GetDrive (.GetDriveName (sFolder) = _ CreateObject ("WScript.Shell"). Environment (_ "Process") ("Home Drive") error then .75 'path / file usage ends the end if End-end sub-sub cleanliness (sFolder) with the object created by end-of-the-box ("scripting.fileSystemObject"). GetFolder (SFolder) 'if recursive before recursive then for each obj. Subfolders cleanup obj next end if' next every obj The oldest files for Delete files. Obj.DateCreated & lt; deleted if deleted deleted + 1 WScript.Echo verb & Obj.Path & amp; "" "if active then obj.Delete (True) End if checked next = Check the +. Files.Count 'and then delete the old or empty folders for each obj.get obj.DateCreated in subfolders & lt; DtOld or 0 = obj.Size then if you wish, count in a variable ... if Active then obj.Delete (True) End If End End with End Sub   

PS Requires a warning about a weak moment Is f São A snapshot folder using collection, which means reaching FSO and does not exist in that folder during the visit. In other words, there is a separate process for removing folders.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -