Consulting

Results 1 to 5 of 5

Thread: VBA to get details of files in a folder

  1. #1

    VBA to get details of files in a folder

    Hi

    I'm using some VBA code to get information on files in a folder.

    for example.

    Cells(r, 2).Formula = FileItem.Size
    Cells(r, 3).Formula = FileItem.Type
    Cells(r, 4).Formula = FileItem.DateCreated
    Cells(r, 5).Formula = FileItem.DateLastAccessed

    Is it possible to add the owner of the file.

    Thanks
    Andy

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings and welcome to VBAX.

    I am probably being thick-headed, but what is FileItem, or where did it come from? FSO, Filesearch?

  3. #3
    [vba]Dim FileItem As Scripting.File
    Dim r As Long
    Set FSO = New Scripting.FileSystemObject
    Set SourceFolder = FSO.GetFolder(SourceFolderName)
    r = Range("A65536").End(xlUp).Row + 1
    For Each FileItem In SourceFolder.Files
    ' display file properties
    Cells(r, 1).Formula = FileItem.Path & FileItem.Name
    Cells(r, 2).Formula = FileItem.Size
    Cells(r, 3).Formula = FileItem.Type
    Cells(r, 4).Formula = FileItem.DateCreated
    Cells(r, 5).Formula = FileItem.DateLastAccessed
    Cells(r, 6).Formula = FileItem.DateLastModified
    Cells(r, 7).Formula = FileItem.Attributes
    Cells(r, 8).Formula = FileItem.ShortPath & FileItem.ShortName
    '''Cells(r, 9).Formula = FileItem.OwnerID
    ' use file methods (not proper in this example)
    ' FileItem.Copy "C:\FolderName\Filename.txt", True
    ' FileItem.Move "C:\FolderName\Filename.txt"
    ' FileItem.Delete True
    r = r + 1 ' next row number
    Next FileItem[/vba]
    Last edited by Aussiebear; 05-17-2010 at 04:27 AM. Reason: Adding VBA tags to code

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Look at Shell and NameSpace here:

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=405

    Hope that helps,

    Mark

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can't get it from FSO, but there is an article here showing how.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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