'======================================================================================================== '======================================================================================================== ' ### Script: dodir.vbs ' ### Created: 06/28/04 ' ### Modified: ' ### Group: AHS ' ### Contact: tim at blackpondfarm.com ' ### Description: Recurse through directories and find last access time for all files ' ### Description: '======================================================================================================== '======================================================================================================== Option Explicit On error resume next 'Declare variables Dim WshShell,Wshnetwork,WshFile Dim Local,Inst Dim strPath,strType Dim objArgs Dim temp Dim objFolder Dim stroutputFile Set WshShell = Wscript.CreateObject("Wscript.shell") Set Wshnetwork = wscript.CreateObject("Wscript.Network") Set Wshfile = wscript.CreateObject("Scripting.FileSystemObject") 'Make sure the host is cscript, if not then set default to cscript if instr(1, wscript.fullname, "cscript.exe", 1) = 0 then VerifyCscript() Set objArgs = WScript.Arguments If objArgs.Count <> 1 Then wscript.echo "Usage: dodir.vbs path" wscript.echo "" wscript.echo "Recurses through all directories and subdirectories in a path and find last access time" wscript.echo "" wscript.quit Else strPath = objArgs(0) End If ParsePath(strPath) '======================================================================================================== '======================================================================================================== sub ParsePath(strPath) On error resume next Dim Temp,Position,number IF INSTR(strPath,"*") THEN Position = instr(strPath,"*") number = len(strPath) strType = lcase(mid(strPath,position+1)) strPath = left(strPath,Position-1) END IF recursedirs wshFile.GetFolder(strPath) End sub '======================================================================================================== '======================================================================================================== Function RecurseDirs(objFolder) On error resume next Dim objSub,INST,ncount,strOut Dim strSource,Position Dim Temp 'Enumerate each file in folder and search for files For Each INST In objFolder.Files strSource = INST.Path IF len(strType) > 0 THEN Position = len(strType) IF lcase((Right(strSource,position))) = lcase(strType) THEN wscript.echo strSource & " " & INST.DateLastAccessed END IF ELSE wscript.echo strSource & " " & INST.DateLastAccessed END IF Next 'Recurse each folder in current folder. For Each objSub In objFolder.SubFolders RecurseDirs objSub Next End Function '======================================================================================================== '======================================================================================================== Function VerifyCscript() Dim temp REM ###### Sets up Vbscript to always run in command window ###### temp = wshshell.Run("cmd /c ""wscript //h:cscript //nologo //s 1>nul 2>nul""", 0, true) temp = MsgBox ("The script has changed the default output of Windows Scripting Host to the command prompt." &_ vbCrLf & "This is pop up is normal, just re-run the script!", 0, "WSH default changed to cscript.") wscript.quit End Function '======================================================================================================== '======================================================================================================== Function screenout(text) Dim wsherrorlogfile On Error Resume Next If (Wshfile.fileexists(strOutputFile)) Then 'If our output file exists, open it, write our data, and close Set wsherrorlogfile = Wshfile.OpenTextFile(strOutputFile, 8) wsherrorlogfile.writeline (text) wsherrorlogfile.Close wscript.DisconnectObject wsherrorlogfile Set wsherrorlogfile = Nothing If Err.number <> 0 Then Err.Clear Else 'File doesn't yet exist, create our output file and write our first line of text Set wsherrorlogfile = Wshfile.createtextfile(strOutputFile, 1) wsherrorlogfile.writeline (text) wsherrorlogfile.Close wscript.DisconnectObject wsherrorlogfile Set wsherrorlogfile = Nothing If Err.number <> 0 Then Err.Clear End If End Function '======================================================================================================== 'END OF SCRIPT '========================================================================================================