Results 1 to 7 of 7

Thread: Question regarding FileSystemObjects

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Question regarding FileSystemObjects

    Is there a way to use FileSystemObjects to put all directories into a List View control, then take a directory the user doubleclicks on, and grab all subdirectories inside it?

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    I undestand that you want to load a Listview control with directories located in let's say your C:\ root directory, plus you want to do something when user DblClicks on some folder. That's clear, but what the hell does this mean???
    "... and grab all subdirectories inside it?"
    Roy

  3. #3
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  4. #4

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    It means I want to compile a list of all the subdirectories inside the directory on which the user clicks. The program is very close to what I want. Here's an example, hopefully it'll help you determine what I want.


    Ok, let's say I have a root folder. The root folder has 3 subfolders: Windows, Program Files, and Temp. I want the code to be refined to where it lists only those folders, and when I doubleclick on one of those folders, it gets all the folder's subfolders and puts double dots as the first item in the Listview, indicating you can go back one directory.

    Here's the code I want refined:

    Code:
    Private Function GetFolders(sStartFolder As String)
    On Error Resume Next
        If status = False Then Exit Function
        Dim fso As New FileSystemObject
        Dim f As Folder
        Dim fldr As Folder
        Set fldr = fso.GetFolder(sStartFolder)
        GetFolders = fldr.Path & vbCrLf
        Debug.Print fldr
        x = x + 1
        Set Litem = ListView1.ListItems.Add(, , x, , 1)
        Litem.SubItems(1) = fldr
        Litem.SubItems(2) = "-"
        Litem.SubItems(3) = Format(fldr.Size, "##,##0.00")
        Litem.SubItems(4) = fldr.Type
        GetFiles (fldr)
        If fldr.SubFolders.Count > 0 Then
            For Each f In fldr.SubFolders
                GetFolders = GetFolders & GetFolders(f.Path)
                DoEvents
            Next f
        End If
    End Function
    Last edited by hothead; Oct 27th, 2002 at 10:59 AM.

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Then why bother with FSO??? Unless you need an extra dependencies in your project, otherwise use built in Dir function. MSDN has pretty good example how to use it. All you will need (generally speaking) is to check if current file is a "folder". If yes then load its name into your Listview control. Plain and simple and what's more important - NO DEPENDENCIES what-so-ever.
    Roy

  6. #6
    New Member
    Join Date
    Oct 2002
    Location
    Kansas City
    Posts
    2
    You will need to recurse similar to your example if you are loading a 'treeview' control with the folders. You might want to do this if you are implementing something that looks like a file explorer and you are pairing this with the listview to show the files. But if you are only doing a listview then I usually store the file type in the .tag property when loading. Then when an item is double clicked I look at the type and if it is a folder then I clear the collection and load the new folder. You can store the current folder path in the .tag of the listview itself and then append to it when you load a sub-folder.

    Likewise, the loadFolder procedure should add a '..' if the folder has a parent with a special tag to indicate a double click should go up. And going up should remove the last folder from the listview's .tag property.

    Hope this helps!
    Glenn Powell
    Software Innovations, Inc.
    http://www.software-innovations-inc.com/

  7. #7
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    If it fits your needs, the simple VB controls for DriveListBox, DirectoryListBox and FileListBox are the simplest.

    They might not always fit your requirements, however, in which case programming your own using a ListBox and the DIR() function will do most things.

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