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!

Echo the most recent folder that contains a specific .jar file

Status
Not open for further replies.

ajspruit911

Technical User
Apr 23, 2010
1
GB
Hi All

I have a build structure that looks something like the below

Build_001
\version.jar
Build_002
\version.jar
Build_003
\

I am trying to return/echo the name of the most recent folder that contain the file version.jar. In the case above even though "build_003" is more recent then "build_002" i want it to return "build_002" as this is the most recent and contains the file version.jar.

Any ideas/help would be very much appreciated

Kindest regards
AJ
 
Using recursion, search a folder and its subfolders for .jar files. When one is found, compare the creation date with the previous files' creation date.

Code:
CONST strDir = "C:\temp\"
CONST strExt = ".jar"

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

function searchForRecentByExt(strDir, strExt)
   set objFolder = objFSO.GetFolder(strDir)
   for each objSubFolder in objFolder.SubFolders
       strRecent = searchForRecentByExt(objSubFolder.Path, strExt)
   next
	
	for each objFile in objFolder.Files
      if (right(objFile.Path, len(strExt)) = strExt) then
			if (len(strRecent) = 0) then
				strRecent = objFile.Path
			else
				set objRecent = objFSO.GetFile(strRecent)
				if (objFile.DateCreated > objRecent.DateCreated) then
					strRecent = objFile.Path
				end if
			end if
		end if
   next
	searchForRecentByExt = strRecent
end function

msgbox searchForRecentByExt(strDir, strExt)

-Geates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top