Re: Delete files older than X days old.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Kenneth Keeley (kenkeeley_at_hotmail.com)
Date: 08/31/04


Date: Wed, 1 Sep 2004 09:34:22 +1000

That page gives great examples like the one I already have but none of them
delete the empty folders from what I can tell. I realy want to delete the
empty folders if possible.

"Dave Patrick" <mail@NoSpam.DSPatrick.com> wrote in message
news:%23qZHBG2jEHA.3852@tk2msftngp13.phx.gbl...
>
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=ux%24%23SGHSCHA.4396%40tkmsftngp09&rnum=3
>
> --
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
>
> "Kenneth Keeley" wrote:
> | Hi,
> | I am looking for a script that could delete all files out of a tree
that
> | are older than X number of days. I would then like it to delete any
> | subfolders that contain no files after the old files are deleted. So far
I
> | have found a script that will delete the files but I am don't how to
> delete
> | the folders.
> |
> | Thanks for any help.
> | Kenneth
> |
> |
> | This is the code for deleting the Files.
> |
> | ' Delete files older than # days...
> | KillDate = Date() - NoOfDays
> |
> | ' Prepare List of Files to Kill.
> | KillList = Array()
> |
> | SelectFiles "D:\FolderToCheck", KillDate, KillList, true
> |
> | for FileCount = 0 to ubound(KillList)
> |
> | on error resume next 'in case of 'in use' files...
> | KillList(FileCount).Delete true
> | next
> |
> | Sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders)
> |
> | ' Get Filesystem Handle.
> | set Filesystem = createobject("scripting.filesystemobject")
> |
> | 'select files to delete and add to array...
> | set folder = Filesystem.getfolder(sPath)
> | set files = folder.files
> |
> | for each file in files
> | ' uses error trapping around access to the
> | ' Date property just to be safe
> | '
> | dtcreated = null
> | on error resume Next
> | dtcreated = file.datecreated
> | on error goto 0
> | if not isnull(dtcreated) Then
> | if dtcreated < vKillDate then
> | count = ubound(arFilesToKill) + 1
> | redim preserve arFilesToKill(count)
> | set arFilesToKill(count) = file
> | end if
> | end if
> | next
> |
> | if bIncludeSubFolders then
> | for each fldr in folder.subfolders
> | SelectFiles fldr.path,vKillDate,arFilesToKill,true
> | next
> | end if
> | end sub
> |
> |
>
>



Relevant Pages

  • Re: Eliminate prompt
    ... Wrote the first requests before I experienced trying to delete multiple ... Automatic search for empty folders on D:\ when script is launched ... Answer yes, all folders deleted, directly followed by the prompt ...
    (microsoft.public.scripting.vbscript)
  • Re: Scripts and soft links.... Problem identified and fixed, sort of.
    ... This morning, I finally discovered the problem, and got the script working. ... lines containing mkdir commands; no clue why, ... and made a COPY of the empty tree of folders, ... empty folders with the appropriate links. ...
    (alt.os.linux)
  • Re: Scripts and soft links.... Problem identified and fixed, sort of.
    ... This morning, I finally discovered the problem, and got the script working. ... lines containing mkdir commands; no clue why, ... and made a COPY of the empty tree of folders, ... empty folders with the appropriate links. ...
    (alt.linux)
  • Re: Searching for empty folders
    ... How Can I List All the Empty Folders on a Specified Drive? ... Set FSO = CreateObject ... Sub ShowSubFolders ... ShowSubFolders Subfolder ...
    (microsoft.public.windowsxp.general)