Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

removeing files/folders by date

1 view
Skip to first unread message

Tim Monkman

unread,
Feb 10, 2001, 12:07:48 PM2/10/01
to
OK,

I thought this would be easy, but it's turning into amatuer night. My
experience is showing through, I would like to create a cscript that can
scan a share for all folders/ subfolder and files and remove and delete
anything older than a certain number of days. I am going through numerous
examples ina couple of books and scripting sites and finding my self more
confused than when I started. I see that I need to use the fso CreationDate
for folders and LasModifiedDate for files and GetFolders for a listing. I
guess the logic skills are in need of polishing. Some guidence and possible
small example would be very much appreciated, but not whole answer. Thanks
much in advance.

-Tim


Michael Harris

unread,
Feb 10, 2001, 5:45:47 PM2/10/01
to
path = "c:\_temp"
arFiles = Array()
killdate = date() - 3

set fso = createobject("scripting.filesystemobject")

SelectFiles path,killdate,arFiles

msgbox ubound(arFiles)

for n = 0 to ubound(arFiles)
set f = arFiles(n)
sFiles = sFiles & f.path & vbcrlf
'=================================================
' Files deleted via FSO methods do *NOT* go to the recycle bin!!!
'=================================================
' When you're *REALLY* sure this works the way you want,
' uncomment the the line below that does the actual delete...
'=================================================
'f.delete true
next

msgbox sFiles

sub SelectFiles(sPath,vKillDate,arFilesToKill)

'select files to delete and add to array...
'
set folder = fso.getfolder(sPath)
set files = folder.files

for each file in files
if file.datelastmodified < vKillDate then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
end if
next

for each fldr in folder.subfolders
SelectFiles fldr.path,vKillDate,arFilesToKill
next

end sub


--
Michael Harris
Microsoft.MVP.Scripting
--
mik...@mvps.org
Please do not email questions - post them to the newsgroup instead.
--

"Tim Monkman" <tmon...@lucent.com> wrote in message news:OqeSbP4kAHA.964@tkmsftngp04...

Tim Monkman

unread,
Feb 12, 2001, 12:05:08 PM2/12/01
to
Mike,

Thanks for the guidence. Just now looking at this, but had been
figuring this out on my own with some examples I found. I want stay on this
path until I get stuck again, which I am now. Right now I have it testing
where I dump the list to a msg box. The problem I am at is I want to run
this as a cscript from the command line which works,but want to put a
prameter on the command line to tell which server to go to, but this is not
working like I thought it might when I create regular batch scripts. In
settting the path I wanted to use like a %1 or %I to look at the parameter
but the path fails later in the code when it goes to execute. example:
cscript cleandate.vbs \\servername\sharename

Here is what I have so far....


Option Explicit

'Declare variables
Const path = "\\servername\sharename"
Dim Text, Title, oFile
Dim fso, oFolder, oFiles, wsh

Text = "Folder "
Title = "Cleandate.vbs"

Set wsh = WScript.CreateObject("WScript.Shell")

'Create FileSystemObject object to access the file system.
Set fso = CreateObject("Scripting.FileSystemObject")

'Get Folder object.
Set oFolder = fso.GetFolder(wsh.ExpandEnvironmentStrings(path))

Text = Text & oFolder & vbCrLf & vbCrLf
Text = Text & "Name" & vbTab & vbTab & "Date" & vbCrLf
Set oFiles = oFolder.Files 'Get Files Collection.


For Each oFile In OFiles 'All Files.
If oFile.DateLastModified <= date()-14 Then
Text = Text & oFile.Name & vbTab
Text = Text & vbTab & oFile.DateLastModified
Text = Text & vbCrLf
End If
Next

MsgBox Text, vbOKOnly + vbInformation, Title

'*** End


"Michael Harris" <mik...@mvps.org> wrote in message
news:eCSF2M7kAHA.1344@tkmsftngp02...

Michael Harris

unread,
Feb 12, 2001, 10:26:44 PM2/12/01
to
You get command line arguments using the WScript.Arguments collection...

WshArguments Object
http://msdn.microsoft.com/scripting/windowshost/doc/wsobjwsharguments.htm

--
Michael Harris
Microsoft.MVP.Scripting
--
mik...@mvps.org
Please do not email questions - post them to the newsgroup instead.
--

"Tim Monkman" <tmon...@lucent.com> wrote in message news:uv17LXRlAHA.1316@tkmsftngp03...

0 new messages