[AccessD] (Really Really OT) - programatically sorting files in a folder

Heenan, Lambert Lambert.Heenan at AIG.com
Fri Feb 14 14:56:00 CST 2003


Oleg,

This is actually real easy to do in VBA - no whacky batch files required.
The savior is that the Dir() function in VBA can take wildcards anywhere so
you can run code like this...

Sub ImportStuff(sDirectory As String, sSuffix As String)
' sSuffix will be "01", "02" etc.
' sDirectory ends in "\"

Dim sFile As String
Dim colFiles As Collection
Dim colItem As Long
' build a collection of file names
    sFile = Dir(sDirectory & "*" & sSuffix & "*.*")
    If sFile & "" = "" Then
        msgbox "No go"
        Exit Sub
    Else
        Set colFiles = New Collection
        While sFile & "" > ""
            colFiles.Add sFile
            sFile = Dir()
        Wend
    End If
    
    With colFiles
        For colItem = 1 To .Count
            Debug.Print .Item(colItem)
            '*********************************************
            ' do your import thing here using .Item(Count)
            ' as the name of your file.
            '*********************************************
        Next colItem
    End With
    Set colFiles = Nothing
End Sub

HTH

Lambert

> -----Original Message-----
> From:	Oleg_123 at xuppa.com [SMTP:Oleg_123 at xuppa.com]
> Sent:	Friday, February 14, 2003 10:09 AM
> To:	accessd at databaseadvisors.com
> Subject:	[AccessD] (Really Really OT) - programatically sorting files
> in a folder
> 
> Hey, since its Friday, i guess i can post an OT question. :)
> I have a folder where I import about 30 files every day. The names are
> almost the same except for last 2 digits. ex. Veronica03 on one day
> Veronica04 or tne next. Can I have a batch file or something that would
> sort them in the order that I need ? (not alphabetical, and it has to
> include wildcards)
> 
> oleg
> 
> 
> -----------------------------------------
> Send a Xuppa Valentine to Your Sweetheart today!
> http://www.xuppa.com/greet/
> 
> 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com



More information about the AccessD mailing list