Results 1 to 5 of 5

Thread: Get Folder Names...

  1. #1
    carp
    Guest

    Get Folder Names...

    I need a sub to get all the folders in a dir. And do this:

    VB Code:
    1. Winsock1.SendData FolderName
    2. FolderName = FolderName + !

    DO you get what I mean?
    Get a folder name, Send the name, Get the next name, Send it and so on until all the folder names have been sent??

  2. #2
    carp
    Guest
    I'm waiting...

  3. #3
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    VB Code:
    1. Private Sub GetFolders(Folderspec as String)
    2.    Dim fso
    3.    dim folderobj
    4.    dim f
    5.    dim subfolder
    6.    dim foldername
    7.  
    8.    set fso = CreateOhject("Scripting.FileSystemObject")
    9.    set folderobj = fso.GetFolder(Folderspec)
    10.    set subfolder = folderobj.SubFolders
    11.  
    12.    For Each f in subfolders
    13.       foldername = f.Name
    14.  
    15.       'do what you want'
    16.    Next
    17. End Sub

    When calling the sub pass it a folder path ("C:\", etc)

  4. #4
    carp
    Guest
    Type MisMatch and it highlights this:

    VB Code:
    1. For Each f In subfolders

    This is how I called it:

    VB Code:
    1. GetFolders("C:\")
    and where you put
    VB Code:
    1. 'Do what you want'
    I changed that to
    VB Code:
    1. List1.AddItem foldername

  5. #5
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Chesterfield, Mi
    Posts
    259
    Try this variation of John McKernan's Code
    VB Code:
    1. Private Sub GetFolders(Folderspec as String)
    2.    Dim fso
    3.    dim folderobj
    4.    dim f
    5.    dim root
    6.    dim foldername
    7.  
    8.    set fso = CreateObject("Scripting.FileSystemObject")
    9.    set folderobj = fso.GetFolder(Folderspec)
    10.    set root = folderobj.Foldername   ' Name or path not sure, no vb near me
    11.  
    12.    For Each f.subfolders in root
    13.       foldername = f.Name
    14.  
    15.       'do what you want'
    16.    Next
    17. End Sub

    I'm not on a vb-enabled box right now,, so do tell me if it works?

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