hexagon logo

How Do I List all files in a folder?

I would like to end up with an array that contains all filenames in a specified folder. I've cobbled together several ways to do this in VB from examples on the net, but none of them work with PC-DMIS's Cypress Enable crap.

How would I do this?

And can I grab specific properties of these files? Like Date/Time Modified?

Thanks!
Parents
  • A fast hack that lists the filenames of all bitmaps in C:\Windows.
    Edit the path and filemask to suit your needs.

    I leave the other properties (modified, timestamp etc.) for you to code.

    [COLOR="YellowGreen"]' Simple filearray
    '
    ' vpt.se 2010[/COLOR]
    
    
    Sub Main()
    Dim FileArray() As String
    Dim FileName As String
    
    [COLOR="YellowGreen"]' Setup Folder And filecounter 
    ' Example lists all bitmaps In C:\Windows[/COLOR]
    Folder = Dir("C:\Windows\*.bmp")
    count = 0
    
    [COLOR="yellowgreen"]' Parse the folder Until filename returns empty (no more files)
    ' And count the files ending With .bmp[/COLOR]
    While Folder <> ""
        count = count + 1
        Folder = Dir
    Wend
    
    [COLOR="yellowgreen"]' The MsgBox is For debug/example purposes And displays the
    ' number of bitmaps found[/COLOR]
    MsgBox "Filecount: " & count
    [COLOR="yellowgreen"]' Initialize the FileArray (create the array) With the size of
    ' count (number of files found)[/COLOR]
    ReDim FileArray(count)
    [COLOR="yellowgreen"]' Fill the filearray With the bitmap filenames[/COLOR]
    FileArray(0) = Dir("C:\Windows\*.bmp")
    
    [COLOR="yellowgreen"]' For debug/example purposes, displays the bitmap filenames[/COLOR]
    For i = 1 To count
        FileArray(i) = Dir
        FileName = FileName + Chr(13) + FileArray(i)
    Next i
    MsgBox FileName
    
    End Sub
    


    Enjoy!

    EDIT: The array FileArray contains the filenames.
Reply
  • A fast hack that lists the filenames of all bitmaps in C:\Windows.
    Edit the path and filemask to suit your needs.

    I leave the other properties (modified, timestamp etc.) for you to code.

    [COLOR="YellowGreen"]' Simple filearray
    '
    ' vpt.se 2010[/COLOR]
    
    
    Sub Main()
    Dim FileArray() As String
    Dim FileName As String
    
    [COLOR="YellowGreen"]' Setup Folder And filecounter 
    ' Example lists all bitmaps In C:\Windows[/COLOR]
    Folder = Dir("C:\Windows\*.bmp")
    count = 0
    
    [COLOR="yellowgreen"]' Parse the folder Until filename returns empty (no more files)
    ' And count the files ending With .bmp[/COLOR]
    While Folder <> ""
        count = count + 1
        Folder = Dir
    Wend
    
    [COLOR="yellowgreen"]' The MsgBox is For debug/example purposes And displays the
    ' number of bitmaps found[/COLOR]
    MsgBox "Filecount: " & count
    [COLOR="yellowgreen"]' Initialize the FileArray (create the array) With the size of
    ' count (number of files found)[/COLOR]
    ReDim FileArray(count)
    [COLOR="yellowgreen"]' Fill the filearray With the bitmap filenames[/COLOR]
    FileArray(0) = Dir("C:\Windows\*.bmp")
    
    [COLOR="yellowgreen"]' For debug/example purposes, displays the bitmap filenames[/COLOR]
    For i = 1 To count
        FileArray(i) = Dir
        FileName = FileName + Chr(13) + FileArray(i)
    Next i
    MsgBox FileName
    
    End Sub
    


    Enjoy!

    EDIT: The array FileArray contains the filenames.
Children
No Data