Results 1 to 4 of 4

Thread: getting all files from folder

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Davis, CA
    Posts
    23
    Is there a way to get all the files from a specific folder(preferably image files), and then load them into an array? (Its for a screen saver that scrolls through all the pictures in a folder). Thanks

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    Check the Dir function. I think if you use it in a loop, you can get the files into an array.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    Use a FileListBox, setting the Path property to where your folder lives, setting the Pattern property to *.img,*.ico for img and ico files (or however you wanna do that), then ReDim a string array.

    Dim MyArray() As String
    filMyFiles.Path = "C:\MyFolder"
    filMyFiles.Pattern="*.img"
    Redim MyArray(filMyFiles.ListCount)
    For i = 1 to filMyFiles.ListCount ' maybe 0 is start index?
    ...

    I forgot if the lowest index of a filelistbox is 0 or 1.

    You can also use the Dir function:

    sFile = Dir("C:\MyFolder", vbDirectory)
    Do While sFile <> ""
    If instr(1,sFile,".img")<>0 Then
    ' add it to your array
    ' problem here is that you might have to
    ' ReDim Preserve along the way
    End If
    sFile = Dir
    Loop


    end war
    stop greed

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
     
     
    Private Sub Form_Load()
        Dim myArr()
        Dim stFile As String, stDir As String
        Dim iCount As Integer
        
        'access all files within the C:\Windows Directory
            stDir = "C:\Windows\"
         
         'here I designate .gif but you can change it to the filetype you use
            stFile = Dir$(stDir & "*.gif")
            
            Do While stFile <> ""
              ReDim Preserve myArr(iCount)
              myArr(iCount) = stDir & "/" & stFile
              iCount = iCount + 1
              stFile = Dir
            Loop
        
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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