Results 1 to 3 of 3

List all files in Directory and Subdirectory with File Property Details

Threaded View

  1. #1
    Registered User
    Join Date
    08-18-2016
    Location
    Earth
    MS-Off Ver
    2010 and 2013
    Posts
    64

    List all files in Directory and Subdirectory with File Property Details

    Hello,

    Is there a way to load and list all files in a directory and subdirectories with the file name AND file property origin detials (author, last editted, last saved by, etc)?
    Some values in the origin details might be blank, and in those cases for that field list it as a blank or FALSE or some other unique identifier.

    I have found code from http://software-solutions-online.com...ubdirectories/ that lists all files in the folder and sub folders, but it does not import the details. Screenshot shows the portion of the file property details I would like to import along with the file paths.

    Option Explicit
    'the first row with data 
    Const ROW_FIRST As Integer = 5 
    
    'This is an event handler. It exectues when the user 
    'presses the run button 
    Private Sub btnGet_Click()
    'determines if the user selects a directory 
    'from the folder dialog 
    Dim intResult As Integer 
    'the path selected by the user from the 
    'folder dialog 
    Dim strPath As String 
    'Filesystem object 
    Dim objFSO As Object
    'the current number of rows 
    Dim intCountRows As Integer 
    Application.FileDialog(msoFileDialogFolderPicker).Title = _
    "Select a Path"
    'the dialog is displayed to the user 
    intResult = Application.FileDialog( _
    msoFileDialogFolderPicker).Show
    'checks if user has cancled the dialog 
    If intResult <> 0 Then 
        strPath = Application.FileDialog(msoFileDialogFolderPicker _ 
        ).SelectedItems(1) 
        'Create an instance of the FileSystemObject 
        Set objFSO = CreateObject("Scripting.FileSystemObject") 
        
        'loops through each file in the directory and prints their 
        'names and path 
        intCountRows = GetAllFiles(strPath, ROW_FIRST, objFSO) 
        'loops through all the files and folder in the input path 
        Call GetAllFolders(strPath, objFSO, intCountRows) 
    End If 
    End Sub 
    
    ''' 
    'This function prints the name and path of all the files 
    'in the directory strPath 
    'strPath: The path to get the list of files from 
    'intRow: The current row to start printing the file names 
    'in 
    'objFSO: A Scripting.FileSystem object. 
    Private Function GetAllFiles(ByVal strPath As String, _
    ByVal intRow As Integer, ByRef objFSO As Object) As Integer 
    Dim objFolder As Object
    Dim objFile As Object
    Dim i As Integer 
    i = intRow - ROW_FIRST + 1
    Set objFolder = objFSO.GetFolder(strPath)
    For Each objFile In objFolder.Files
            'print file name 
            Cells(i + ROW_FIRST - 1, 1) = objFile.Name 
            'print file path 
            Cells(i + ROW_FIRST - 1, 2) = objFile.Path 
            i = i + 1 
    Next objFile
    GetAllFiles = i + ROW_FIRST - 1
    End Function
    
    ''' 
    'This function loops through all the folders in the 
    'input path. It makes a call to the GetAllFiles 
    'function. It also makes a recursive call to itself 
    'strFolder: The folder to loop through 
    'objFSO: A Scripting.FileSystem object 
    'intRow: The current row to print the file data on 
    Private Sub GetAllFolders(ByVal strFolder As String, _
    ByRef objFSO As Object, ByRef intRow As Integer) 
    Dim objFolder As Object
    Dim objSubFolder As Object
    
    'Get the folder object 
    Set objFolder = objFSO.GetFolder(strFolder)
    'loops through each file in the directory and 
    'prints their names and path 
    For Each objSubFolder In objFolder.subfolders
        intRow = GetAllFiles(objSubFolder.Path, _ 
            intRow, objFSO) 
        'recursive call to to itsself 
        Call GetAllFolders(objSubFolder.Path, _ 
            objFSO, intRow) 
    Next objSubFolder
    End Sub
    origindetails.PNG

    I hope my request makes sense. Data to show across multiple columns will be ideal, but if will load info in single cell, as long as there is some type of delimiter between each field.

    Thank you in advance and please let me know if you would like me to clarify anything.
    Last edited by Green Crocodile; 08-26-2016 at 03:24 PM. Reason: Added VBA code from SSO

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. list subfolders and files of main folder with details
    By buerere in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-21-2014, 10:44 AM
  2. Replies: 0
    Last Post: 03-13-2013, 09:08 PM
  3. Sorting list of files in a directory using the File System Object (FSO)
    By gincemathew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2013, 01:50 PM
  4. Excel File Directory - List NEW Files only
    By lilanngel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2013, 03:54 PM
  5. List all files in directory in an Excel file
    By hutch@edge.net in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-03-2009, 11:58 AM
  6. List Files in a Directory
    By plantechbl@earthlink.net in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2005, 08:15 PM
  7. [SOLVED] Return most recent file in subdirectory with out using FileSearch
    By Enohp Aikon in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-03-2005, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1