Need a VBScript to compare file path and extract the folder name with greastest number

I have a script that extracts the subfolder names.  The root folder has a numeral name, which equates to the latest folder created and newest contents.  I will need to compare all the folders and copy the "one" folder name with the highest number.  I have the path of all the folder names listed after my script.  I will need a script to compare the last 4 digits at the end of these paths and determine the one with the highest number.  In my case, 4799 would be the highest number or most current folder.  

OUTPUT

\\server\install\System\Builds\4684
\\server\install\System\Builds\4694
\\server\install\System\Builds\4797
\\server\install\System\Builds\4799
On Error Resume Next
 
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder("\\server\install\System\Builds\")
 
Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
            Wscript.Echo Subfolder.Path
        'ShowSubFolders Subfolder
    Next
End Sub

Open in new window

moorejcAsked:
Who is Participating?
 
Shift-3Connect With a Mentor Commented:
This should do it.


On Error Resume Next
 
strFolder = "\\server\install\System\Builds"
 
intHighest = 0
 
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubFolders FSO.GetFolder(strFolder)
 
WScript.Echo strFolder & "\" & intHighest
 
Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
            If Subfolder.Name > intHighest Then
                intHighest = Subfolder.Name
            End If
        'ShowSubFolders Subfolder
    Next
End Sub

Open in new window

0
 
leh327Commented:
right(Subfolder.Path,4)
will give you the last 4 characters to do comparison.
0
 
moorejcAuthor Commented:
Thank you sift-3.  -- worked out great.  Why did you have "\" in the Wscript echo line?
0
 
Shift-3Commented:
The value of the intHighest variable is just the folder name.  Echoing the full path requires concatenating the strFolder variable, a backslash, and then intHighest.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.