?
Solved

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

Posted on 2009-02-19
4
Medium Priority
?
841 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:moorejc
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 total points
ID: 23686293
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
 
LVL 2

Expert Comment

by:leh327
ID: 23686314
right(Subfolder.Path,4)
will give you the last 4 characters to do comparison.
0
 

Author Closing Comment

by:moorejc
ID: 31548888
Thank you sift-3.  -- worked out great.  Why did you have "\" in the Wscript echo line?
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 23692413
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question