PC Review


Reply
Thread Tools Rate Thread

Delete files older than X days old.

 
 
Kenneth Keeley
Guest
Posts: n/a
 
      31st Aug 2004
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


 
Reply With Quote
 
 
 
 
Dave Patrick
Guest
Posts: n/a
 
      31st Aug 2004
http://groups.google.com/groups?hl=e...ftngp09&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
|
|


 
Reply With Quote
 
Kenneth Keeley
Guest
Posts: n/a
 
      1st Sep 2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>

http://groups.google.com/groups?hl=e...ftngp09&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
> |
> |
>
>



 
Reply With Quote
 
Dave Patrick
Guest
Posts: n/a
 
      1st Sep 2004
It is only supposed to be one example. The line;

SelectFiles path, killdate, arFiles, true

sets the boolean bIncludeSubFolders to true so that the following can run

if bIncludeSubFolders then
for each fldr in folder.subfolders
SelectFiles fldr.path,vKillDate,arFilesToKill,true
next
end if

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Kenneth Keeley" wrote:
| 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete files older than X days babu Microsoft Windows 2000 CMD Promt 8 22nd Apr 2011 04:21 AM
delete all files, which older than 5 days Thomas Bauer Microsoft C# .NET 2 8th Jan 2008 08:05 PM
Re: "delete files older than X (working) days" BEN.RITCHEY@family-news.org Freeware 0 13th Feb 2005 08:08 AM
how to delete folders and files older than 14 days old Eric Microsoft Windows 2000 Security 5 15th Dec 2004 10:27 PM
Re: delete backup files older than 10 days Jonathan de Boyne Pollard Microsoft Windows 2000 CMD Promt 0 21st Jul 2003 03:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:34 PM.