Script to Identify File Creation, Modification, and Access Times
10/12/08
Script to Identify File Creation, Modification, and Access Times
This script will identify files that have been created, accessed, or modified in the last 30 minutes and depending on how you want it to act, it can delete the identified files.
I received a request for this script from the scripting request form. The requirements from this request were, i needed your help in the Wsh scripting to delete the files created or access 30 minutes back in a paticular folderthanks in advance .
'----------------------------------------------------------
'- Identify Old Files VBScript sample
'-
'- Copyright © 2008, Dave Moats
'-
'- This sample is provided 'AS-IS', without any
'- express or implied warranty. In no event will the
'- authors be held liable for any damages arising from
'- the use of this sample code.
'-
'- Permission is granted to anyone to use this sample
'- code for any purpose, including commercial applications,
'- subject to the following restrictions:
'-
'- The origin of this code must not be misrepresented;
'- you must not claim that you wrote the original code.
'-
'- If you use this code, an acknowledgment in the
'- documentation is requested - shown below:
'-
'- Portions Copyright © 2008,
'- Dave Moats (http://www.davemoats.com/).
'-
'----------------------------------------------------------
'----------------------------------------------------------
'- NOTE: watch for wrapped lines and html special
'- characters in the web representation of this
'- sample code
'----------------------------------------------------------
option explicit
dim fso
dim folderName
dim days
dim targetDir
dim oldDate
dim fileObj
if wscript.arguments.count = 0 then
wscript.echo "Usage: cscript delOldFiles.vbs <foldername>"
wscript.quit()
else
folderName = wscript.arguments.item(0)
end if
set fso = createobject( "scripting.filesystemobject" )
set targetDir = fso.getfolder( folderName )
oldDate = DateAdd("n", -30, Date)
for each fileObj in targetDir.Files
'-------------------------------------------------------
'- find the old files - if you just want the files that
'- have been created or accessed NOT modified in the last
'- 30 minutes, remove this check fileObj.datelastmodified
'- >= oldDate
'-------------------------------------------------------
if fileObj.datecreated >= oldDate or fileObj.datelastmodified >= oldDate or fileObj.datelastaccessed >= oldDate then
'----------------------------------------------------
' to delete the files, uncomment the line bleow
'----------------------------------------------------
' fso.deletefile(fileObj.path)
wscript.echo "File match - " & fileObj.name & " - " & fileObj.datecreated & " - " & fileObj.datelastmodified & " - " & fileObj.datelastaccessed
end if
next
set targetDir = nothing
set fso = nothing
wscript.quit()
Pay close attention to the html specific special characters and the lines wrapping in this sample, the script does not have any multi-line statements.
I hope this post helped out. If it didn't, post a response to this blog and we can work through it.
As always, I am always looking for new scripts to add to this site, so submit a request for your question or need and I will see if I can answer it.
Dave
Pingbacks:
No Pingbacks for this post yet...
Scripts
This is somewhere I can post interesting snippets as I come across them. Hopefully some folks out there will find this helpful.
Search
Follow Me:
Categories
- All
- Web Technologies (2)
- PHP (1)
- Windows Scripting (37)
- Batch Scripts (13)
- Wsh Scripts (23)
Archives
- December 2009 (2)
- March 2009 (2)
- February 2009 (3)
- January 2009 (2)
- December 2008 (4)
- November 2008 (1)
- October 2008 (1)
- February 2008 (1)
- December 2007 (3)
- July 2007 (1)
- April 2007 (1)
- February 2007 (2)
- More...
Misc
Who's Online?
- Guest Users: 3




