Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get File Date last modified

Status
Not open for further replies.
Mar 8, 2004
89
CA
I am looking to build a script to run against a network folder containing a number of files / folders and export out preferably to a spreadsheet the last modified date of the files.

Being the main folder contains a number of sub folders which contain additional folders and files, I may have to run something on each folder, but figured if I could get in an Excel format I could do the sorting in the spreadsheet itself.

I have written a few scripts to remove or move files older then a certain date, but never one to just report the date.

Any help would be greatly appreciated

thanks


Mark Morton CCA,MCITP,MCTS,MCSA,SNA,SERVER+
 
It might be easiest to log the data in CSV format. This template gives you that.
Code:
'===============================================================================
' NAME: TemplateWithLogging.vbs
' AUTHOR: Jeff "MasterRacker"
' DATE: 05/22/2009
' DESCRIPTION: 
'     Template for a script that needs logging.
'     The information is logged to the specified file in CSV format.
'===============================================================================
dim FSO, outFQN

if Wscript.Arguments.Count < 1 then
	Wscript.echo ("USAGE: Template <logfile>")
	Wscript.Quit
end if

'========================= Logfile Initialization	- Start
set FSO = WScript.CreateObject("Scripting.FileSystemObject")
outFQN  = Wscript.Arguments(0)

'----- If the output file does not exist, create it
if not FSO.FileExists(outFQN) then
   set outFile = FSO.CreateTextFile(outFQN)
end if
set outFile = nothing

'----- Open file for append
const ForAppending = 8
set outFile = FSO.OpenTextFile (outFQN, ForAppending, true)
'========================= Logfile Initialization	- End

'----- Do stuff here

For Each blah in blahblah
	outFile.WriteLine ( Date() & "," & "stuff here...")
Next

'----- Cleanup
set FSO = nothing
outFile.Close
Wscript.Quit
'================================= END OF FILE =================================
Sounds like you already know how to read a folder and get dates, so this should give you a start.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
traverse the directory and report file modify dates

Code:
strFolder = "C:\temp\"
strOutput = "output.txt"

set objFSO = CreateObject("Scripting.FileSystemObject")
set objOutput = objFSO.OpenTextFile(strFolder & "\" & strOutput, 8, true)
set objShell = CreateObject("WScript.Shell")

function traverseDir(strDir)
	set objFolder = objFSO.GetFolder(strDir)
	
	for each objSubFolder in objFolder.SubFolders
		traverseDir objSubFolder.Path
		strContent = strContent & strResults
	next
	
	for each objFile in objFolder.Files
		objOutput.WriteLine objFile.Path & ", " & objFile.DateLastModified
	next
end function

traverseDir strFolder

objOutput.close
objShell.Run(strFolder & "\" & strOutput)

-Geates
 
damnit! Another correction...

Code:
strFolder = "C:\temp"
strOutput = "output.txt"

set objFSO = CreateObject("Scripting.FileSystemObject")
set objOutput = objFSO.OpenTextFile(strFolder & "\" & strOutput, 8, true)
set objShell = CreateObject("WScript.Shell")

function traverseDir(strDir)
    set objFolder = objFSO.GetFolder(strDir)
    for each objSubFolder in objFolder.SubFolders
		strContent = strContent & traverseDir(objSubFolder.Path)
	next
	
	for each objFile in objFolder.Files
		objOutput.WriteLine objFile.Path & ", " & objFile.DateLastModified
	next
	traverseDir = strContent
end function

traverseDir strFolder

objOutput.close
objShell.Run(strFolder & "\" & strOutput)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top