Link to home
Start Free TrialLog in
Avatar of moorejc
moorejcFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leh327
leh327

right(Subfolder.Path,4)
will give you the last 4 characters to do comparison.
Avatar of moorejc

ASKER

Thank you sift-3.  -- worked out great.  Why did you have "\" in the Wscript echo line?
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.