Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hoiw to change file sorting with fileSystemObject?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
0
0
AU
I have written a simple vb6 slideshow to show my camera pics on a 1920 x 1080 LCD TV set via HDMI using the usual filesystemobject method. (They look fantastic)

Question:-
All the files in one folder seem to show in turn in order of date created.
Is there a way of extracting the filenames in any other given order without resorting the array afterwards? (such as alphabetically by name or size like you can with Windows explorer)

This is how I create the list for showing:-
Code:
Sub MakeFileList(FilePath as string)
Dim fs, f, f1, fc, TempFile As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(Filepath)
Set fc = f.Files
Erase FileCollection
FileCount = 0
For Each f1 In fc
    If FileCount < 1000 Then
        TempFile = f1.Name 'read next item in folder
        If LCase(Right(TempFile, 3)) = "jpg" Or LCase(Right(ThisFile, 3)) = "bmp" Then
            FileCollection(FileCount) = TempFile  'put all filenames in the folder into an array
            FileCount = FileCount + 1
            DoEvents
        End If
    Else
        MsgBox "Can't show more than 1000 files in one folder"
    End If
Next
TotalFiles.Caption = FileCount
End Sub

Sub Timer1_OnTimer()
'5 second timer to show slides
If FilePosn<1000 then FilePosn=FilePosn+1
Set Image1.Picture = LoadPicture(FileCollection(FilePosn)
)
End Sub
'other controls are used to stop & start sequence, vary time and select the folder to show.
The Image control is within a frame so I can adjust the cropping for the wide screen TV.
 

Yes, instead of putting the files in an limited array, you could use a disconnected ADODB.Recordset, adding the files as records and sort the recordset the way you like. Just use as many fields as the different sorting orders you need, indexing them could speed up the sorting process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top