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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to check files in dir older than 30 mins

Status
Not open for further replies.

SoniaSinha

Programmer
Mar 28, 2011
1
US
Hi All,

I am looking for VB script to monitor BizTalk
folder/dir and more than hundred files inside the folder.

The script should monitor the Folder/dir and alert user anytime a file has been sitting in the directory for more than 30 minutes.
Sonia
 
Actually, the solution I provided for the previous thread ( would work with a little tweak.

You need to recursively traverse a directory and test the .DateLastModified property of every file encountered against now() to determine it's age. If the file is older that intAgeInMinutes, then the file name(s) is/are returned.

Code:
intAgeInMinutes = 30
strDir = "C:\temp\"

set objShell = CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")

function searchForLoiteringsFile(strDir)
	set objFolder = objFSO.GetFolder(strDir)
	for each objSubFolder in objFolder.SubFolders
		strFiles = searchForLoiteringFiles(objSubFolder.Path)
	next
	
	for each objFile in objFolder.Files
		if (datediff("n", objFile.DateLastModified, now) > intAgeInMinutes) then
			strFiles = strFiles & objFile.Path
		end if
	next
	searchForLoiteringFiles = strFiles
end function

msgbox searchForLoiteringFiles(strDir)

-Geates

Note: In the threade before, I eluded that recursively traversing network directories may considerable slow, depending on how the network is configured.

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Corrections. Typos

strFiles = strFiles & objFile.Path
strFiles = strFiles & objFile.Path [red]& vbNewLine[/red]

and

function searchForLoiteringsFile(strDir)
function searchForLoiteringFile[red]s[/red](strDir)

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top