Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How can I load the files in a folder into a regular listbox

HGeneAnthonyHGeneAnthony Member Posts: 92
I want to be able to specify to load all files ending in .gif or .jpeg into a regular listbox. I'm using a regular listbox because I've had problems in the past loading files with the filelistbox control. I'll specify a folder to load files from and it'll default to a different folder. Then the next time I'll load the project it'll work. I don't know what causes this but it's happened repeately.

Comments

  • GenjuroGenjuro Member Posts: 913
    : I want to be able to specify to load all files ending in .gif or .jpeg into a regular listbox. I'm using a regular listbox because I've had problems in the past loading files with the filelistbox control. I'll specify a folder to load files from and it'll default to a different folder. Then the next time I'll load the project it'll work. I don't know what causes this but it's happened repeately.
    :

    Use the "Dir" function (or the much-hated FileSystem Object) to get the file names, then just "Add" them in the ListBox.

  • HGeneAnthonyHGeneAnthony Member Posts: 92
    : : I want to be able to specify to load all files ending in .gif or .jpeg into a regular listbox. I'm using a regular listbox because I've had problems in the past loading files with the filelistbox control. I'll specify a folder to load files from and it'll default to a different folder. Then the next time I'll load the project it'll work. I don't know what causes this but it's happened repeately.
    : :
    :
    : Use the "Dir" function (or the much-hated FileSystem Object) to get the file names, then just "Add" them in the ListBox.
    :
    :
    Thanx for the reply. I couldn't remember how to do it. I was also wondering how can I loop through all files in the folder until I reach the end?
  • GenjuroGenjuro Member Posts: 913
    : : : I want to be able to specify to load all files ending in .gif or .jpeg into a regular listbox. I'm using a regular listbox because I've had problems in the past loading files with the filelistbox control. I'll specify a folder to load files from and it'll default to a different folder. Then the next time I'll load the project it'll work. I don't know what causes this but it's happened repeately.
    : : :
    : :
    : : Use the "Dir" function (or the much-hated FileSystem Object) to get the file names, then just "Add" them in the ListBox.
    : :
    : :
    : Thanx for the reply. I couldn't remember how to do it. I was also wondering how can I loop through all files in the folder until I reach the end?
    :

    If you're using Dir, then each call to "Dir()" besides the first will return you one more file, until there are no more (and then, Dir() returns "").
    If you're using the FileSystemObject, then a "For each... next" will suffice.
  • HGeneAnthonyHGeneAnthony Member Posts: 92
    : : : : I want to be able to specify to load all files ending in .gif or .jpeg into a regular listbox. I'm using a regular listbox because I've had problems in the past loading files with the filelistbox control. I'll specify a folder to load files from and it'll default to a different folder. Then the next time I'll load the project it'll work. I don't know what causes this but it's happened repeately.
    : : : :
    : : :
    : : : Use the "Dir" function (or the much-hated FileSystem Object) to get the file names, then just "Add" them in the ListBox.
    : : :
    : : :
    : : Thanx for the reply. I couldn't remember how to do it. I was also wondering how can I loop through all files in the folder until I reach the end?
    : :
    :
    : If you're using Dir, then each call to "Dir()" besides the first will return you one more file, until there are no more (and then, Dir() returns "").
    : If you're using the FileSystemObject, then a "For each... next" will suffice.
    :

    Thanx for your help could you please tell me though how I can alter the following code to filter out more than one file type.

    '''''''''''''''''''''''''''''''''''''''''''
    myFile = Dir$(App.Path & "Pics" & "*.jpg")
    Do Until myFile = ""
    myFile = Dir$
    If myFile = "" Then
    Else
    listPics.AddItem myFile
    End If
    Loop
    '''''''''''''''''''''''''''''''''''''''''''

    I tried using it again right afterwards but it didn't show the gifs.
    Is there a way to use an Or operator with this?
  • KDivad LeahcimKDivad Leahcim Member Posts: 3,948
    : : : : : I want to be able to specify to load all files ending in .gif or .jpeg into a regular listbox. I'm using a regular listbox because I've had problems in the past loading files with the filelistbox control. I'll specify a folder to load files from and it'll default to a different folder. Then the next time I'll load the project it'll work. I don't know what causes this but it's happened repeately.
    : : : : :
    : : : :
    : : : : Use the "Dir" function (or the much-hated FileSystem Object) to get the file names, then just "Add" them in the ListBox.
    : : : :
    : : : :
    : : : Thanx for the reply. I couldn't remember how to do it. I was also wondering how can I loop through all files in the folder until I reach the end?
    : : :
    : :
    : : If you're using Dir, then each call to "Dir()" besides the first will return you one more file, until there are no more (and then, Dir() returns "").
    : : If you're using the FileSystemObject, then a "For each... next" will suffice.
    : :
    :
    : Thanx for your help could you please tell me though how I can alter the following code to filter out more than one file type.
    :
    : '''''''''''''''''''''''''''''''''''''''''''
    : myFile = Dir$(App.Path & "Pics" & "*.jpg")
    : Do Until myFile = ""
    : myFile = Dir$
    : If myFile = "" Then
    : Else
    : listPics.AddItem myFile
    : End If
    : Loop
    : '''''''''''''''''''''''''''''''''''''''''''
    :
    : I tried using it again right afterwards but it didn't show the gifs.
    : Is there a way to use an Or operator with this?
    :
    This is what I would do:
    [code]
    Dim t As String
    ChDrive Left$(FolderName, 2)
    ChDir FolderName
    t = Dir$("*.jpg")
    Do Until t = ""
    List1.AddItem t
    t = Dir$
    Loop
    t = Dir$("*.gif")
    Do Until t = ""
    List1.AddItem t
    t = Dir$
    Loop
    [/code]
    Your other options that I can think of are to use Dir with *.* and examine each file as it is returned (especially since all patterns passed to Dir have an implicit * on the end. For ex, *.gif will return *.gif3 and *.gifr as well) and add it if it matches what you want. Or use a filelistbox and set the pattern to "*.gif;*.jpg" and then copy each one out (filelistbox has same problem as Dir. Examine each name).
  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ________ { http://forcoder.org } free video tutorials and ebooks about // Delphi Ruby Swift Go Visual Basic .NET MATLAB Java R JavaScript Perl C# C++ Visual Basic PHP Assembly Objective-C PL/SQL C Scratch Python Awk Transact-SQL Alice LabVIEW VBScript Hack Scala Bash SAS Kotlin Scheme F# Erlang Prolog Ada Julia ABAP Crystal Apex Lisp Rust FoxPro D Clojure COBOL Logo Lua ML Fortran Dart // _______

Sign In or Register to comment.