Results 1 to 2 of 2

Thread: RESOLVED[File listing script]

Threaded View

  1. #1

    Thread Starter
    Addicted Member Fonty's Avatar
    Join Date
    May 2006
    Location
    New York
    Posts
    173

    Resolved RESOLVED[File listing script]

    I'm doing a list of files and it's properties for some files contained in some subdirectories. For this I'm using a script I found here , for which I have only few options like these:

    VB Code:
    1. Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
    2. Dim SourceFolder As Scripting.Folder
    3. Dim SubFolder As Scripting.Folder
    4. Dim FileItem As Scripting.File
    5. Dim r As Long
    6.     Set FSO = New Scripting.FileSystemObject
    7.     Set SourceFolder = FSO.GetFolder(SourceFolderName)
    8.     r = Range("A65536").End(xlUp).Row + 1
    9. ' File properties:
    10.     For Each FileItem In SourceFolder.Files
    11.         Cells(r, 1).Formula = FileItem.ParentFolder
    12.         Cells(r, 2).Formula = FileItem.Name
    13.         Cells(r, 3).Formula = FileItem.Size
    14.         Cells(r, 4).Formula = FileItem.Type
    15.         Cells(r, 5).Formula = FileItem.DateCreated
    16.         Cells(r, 6).Formula = FileItem.DateLastAccessed
    17.         Cells(r, 7).Formula = FileItem.DateLastModified
    18.         Cells(r, 8).Formula = FileItem.Drive
    19.         r = r + 1
    20.     Next FileItem
    21.     If IncludeSubfolders Then
    22.         For Each SubFolder In SourceFolder.SubFolders
    23.             ListFilesInFolder SubFolder.Path, True
    24.         Next SubFolder
    25.     End If
    26.     Set FileItem = Nothing
    27.     Set SourceFolder = Nothing
    28.     Set FSO = Nothing
    29. End Sub

    What I want to add is the name of individual subfloders. For example, for 2 files:
    C:\folder\subfolder1\subfolder2\file1
    C:\folder\subfolder1\file2

    I'd like to have

    Name Folde1 Folder2 Folder3
    file1 folder subfolder1 subfolder2
    file2 folder subfolder1

    I'm able to do something like this using MID() and FIND() instructions in the sheet, however I'd like to automate it.
    Last edited by Fonty; Jun 13th, 2006 at 10:04 PM.

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