Results 1 to 8 of 8

Thread: Files [Resolved]

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Files [Resolved]

    Given a folder path, what would be the easiest way to loop through and find all filenames and folder names in the given path? Thanks.
    Last edited by Nove; Oct 23rd, 2005 at 11:04 AM.

  2. #2
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Files

    Does it have to be in the code? Because you can use a FileListBox and in Form_Load event put File1.Path = "Location of folder"

  3. #3

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Files

    I have to be able to retreive the filepaths of the folders and files so I can work with them programatically.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Files

    This loads the jpg images from a folder into a listbox, but you can change it to suit your wishes.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim FileFinder$
    5.   FileFinder = Dir("d:\temp\*.jpg")
    6.   Do Until FileFinder = ""
    7.     List1.AddItem LCase(FileFinder)
    8.     FileFinder = Dir
    9. Loop
    10. End Sub

  5. #5

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Files

    Ok, that'll work great. Now, how would I find all the folders in the specified path?

  6. #6
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Files

    Try this code, it will walk the directory structure and give you all the folders and files within that directory. This example will fill a treeview with the same tree structure as the directory.
    VB Code:
    1. Private Sub ShowFolder(ByVal sFolder As String)
    2.     Dim sDir As String
    3.     Dim coll As Collection
    4.     Dim i As Long
    5.     Set coll = New Collection
    6.     sDir = Dir(sFolder & "\", vbDirectory + vbHidden + vbReadOnly)
    7.     With TreeView1
    8.         Do While sDir <> ""
    9.             If (GetAttr(sFolder & "\" & sDir) And vbDirectory) = vbDirectory Then
    10.                 If sDir <> "." And sDir <> ".." Then
    11.                     .Nodes.Add sFolder, tvwChild, sFolder & "\" & sDir, sDir
    12.                     coll.Add sFolder & "\" & sDir
    13.                 End If
    14.             Else    'It may be a file
    15.                 .Nodes.Add sFolder, tvwChild, sFolder & "\" & sDir, sDir
    16.             End If
    17.             sDir = Dir
    18.         Loop
    19.         .Nodes(sFolder).Sorted = True
    20.     End With
    21.     For i = 1 To coll.Count
    22.         ShowFolder coll(i)
    23.     Next
    24.     Set coll = Nothing
    25. End Sub
    26.  
    27. Private Sub Command1_Click()
    28.     With TreeView1
    29.         .Nodes.Clear
    30.         .Nodes.Add , , Text1.Text, Dir(Text1.Text, vbDirectory)
    31.         ShowFolder Text1.Text
    32.     End With
    33. End Sub

    hope this helps
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  8. #8

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Files

    Ok, thanks.

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