Results 1 to 2 of 2

Thread: Sorting Folder Contents

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Sorting Folder Contents

    Hi All,

    I have a drive (lets call it "H") that will have a dynamic list of folders within it. The folders will work off of a date naming convention, example 20071105.

    I need to be able to sort the contents of the "H" drive and return the oldest folder using a .vbs script.

    For Example:

    "H" Drive contents:

    20071119
    20071105
    20070509
    20071126
    20071203
    20070912
    20071112

    I would like to return the oldest folder name. In this case, 20070509.

    Any help would greatly be appreciated. Thank you!

  2. #2
    Lively Member Spetnik's Avatar
    Join Date
    Jan 2002
    Posts
    121

    Re: Sorting Folder Contents

    Code:
    Function getLowestMatch(arrIn())
    Dim i, j, strBuff
        
        strBuff = arrIn(LBound(arrIn))
        For i = LBound(arrIn) + 1 To UBound(arrIn)
            If strBuff > arrIn(i) Then
                strBuff = arrIn(i)
            End If
        Next
        
        getLowestMatch = strBuff
        
    End Function
    
    Dim oFS, oFolder, oFCol
    Dim arrFolders(), i
        
        Set oFS = CreateObject("Scripting.FileSystemObject")
        Set oFCol = oFS.GetFolder("H:\").SubFolders
        
        ReDim arrFolders(0)
        i = 0
        For Each oFolder In oFCol
           arrFolders(UBound(arrFolders)) = oFolder.Name
           ReDim Preserve arrFolders(UBound(arrFolders) + 1)
        Next
        
        ReDim Preserve arrFolders(UBound(arrFolders) - 1)
        
        MsgBox getLowestMatch(arrFolders)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width