Results 1 to 5 of 5

Thread: How do I "dir" all sub folders and files ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    87

    Post

    How do I "dir" all sub folders and files from a specified root Directory e.g Drive, and add all found files & folders into a Treeview, including Sub Folders ???
    Please I really, really, need an example on how to do this.
    :-)

  2. #2
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    oh, sorry
    well, I'll have a look for it.

    by the way: this function adds subfolders, too

    ------------------
    Razzle
    ICQ#: 31429438

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Post

    for all the functions you need to do this add a reference (from project-references) to MS scripting. use the object viewer (F2) to look at the functions. there are lots for file and folder (and properties thereof) manipulation.

    email me if you need details

  4. #4
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    'Put this in a module:
    Public Const MAX_PATH = 259

    Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
    End Type

    Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
    End Type

    Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

    Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
    Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
    Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
    Public Const FILE_ATTRIBUTE_HIDDEN = &H2
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Public Const FILE_ATTRIBUTE_READONLY = &H1
    Public Const FILE_ATTRIBUTE_SYSTEM = &H4
    Public Const FILE_ATTRIBUTE_TEMPORARY = &H100


    'and this to a form with a listbox on it

    Sub GetAllFiles(directory$, mask$)
    Dim rec As WIN32_FIND_DATA
    Dim filename$
    Dim fh&
    DoEvents
    If Right(directory, 1) <> "\" Then directory = directory & "\"
    fh = FindFirstFile(directory & mask, rec)
    If fh = 0 Then Exit Sub
    Do
    filename = Left(rec.cFileName, InStr(rec.cFileName, Chr(0)) - 1)
    If (rec.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
    If (filename <> ".") And (filename <> "..") Then GetAllFiles directory & filename, mask : List1.additem directory
    Else
    List1.AddItem directory & filename
    End If
    Loop While FindNextFile(fh, rec)
    FindClose fh
    End Sub


    ------------------
    Razzle
    ICQ#: 31429438

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    87

    Post

    Thanks, but what I really wanted was to AddItems to a TREEVIEW with SUBFOLDERS in it, so it creates a directory structure in a TREEVIEW.
    Please help. =)

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