+ Reply to Thread
Results 1 to 4 of 4

Getting a List of File Names

  1. #1
    gilgil
    Guest

    Getting a List of File Names

    I want fo get in a worksheet a list of all files in a particular directory.
    For each file in the folder I want to get: name, size and date.
    Thanks.
    --
    gilgil259

    Antispam: replace 259 with 159




  2. #2
    Norman Jones
    Guest

    Re: Getting a List of File Names

    Hi Gilgil,

    Try the following which was previously posted by Jim Thomlinson::
    '=============>>
    Sub ListFiles()
    Dim fso As New FileSystemObject
    Dim oCurrentFile As File
    Dim oCurrentFolder As Folder
    Dim wks As Worksheet
    Dim rng As Range

    Set wks = Sheets("Sheet1")
    Set rng = wks.Range("A2")

    Set oCurrentFolder = fso.GetFolder("C:\Windows")

    For Each oCurrentFile In oCurrentFolder.Files
    rng.Value = oCurrentFile.Name
    rng.Offset(0, 1).Value = oCurrentFile.ShortName
    rng.Offset(0, 2).Value = oCurrentFile.Path
    rng.Offset(0, 3).Value = oCurrentFile.DateCreated
    rng.Offset(0, 4).Value = oCurrentFile.DateLastAccessed
    rng.Offset(0, 5).Value = oCurrentFile.DateLastModified
    rng.Offset(0, 6).Value = oCurrentFile.Size
    rng.Offset(0, 7).Value = oCurrentFile.Type
    rng.Offset(0, 8).Value = oCurrentFile.Attributes
    Set rng = rng.Offset(1, 0)
    Next oCurrentFile
    End Sub
    '<<=============


    ---
    Regards,
    Norman



    "gilgil" <[email protected]> wrote in message
    news:[email protected]...
    >I want fo get in a worksheet a list of all files in a particular directory.
    > For each file in the folder I want to get: name, size and date.
    > Thanks.
    > --
    > gilgil259
    >
    > Antispam: replace 259 with 159
    >
    >
    >




  3. #3
    Norman Jones
    Guest

    Re: Getting a List of File Names

    Hi Gilgil,

    Just to add, to use this code you will need to add a reference in the VBE to
    the Microsft Scripting Runtime library. In the VBE:

    Tools | References | Check 'Microsoft Scripting Runtime'

    ---
    Regards,
    Norman



    "Norman Jones" <[email protected]> wrote in message
    news:%[email protected]...
    > Hi Gilgil,
    >
    > Try the following which was previously posted by Jim Thomlinson::
    > '=============>>
    > Sub ListFiles()
    > Dim fso As New FileSystemObject
    > Dim oCurrentFile As File
    > Dim oCurrentFolder As Folder
    > Dim wks As Worksheet
    > Dim rng As Range
    >
    > Set wks = Sheets("Sheet1")
    > Set rng = wks.Range("A2")
    >
    > Set oCurrentFolder = fso.GetFolder("C:\Windows")
    >
    > For Each oCurrentFile In oCurrentFolder.Files
    > rng.Value = oCurrentFile.Name
    > rng.Offset(0, 1).Value = oCurrentFile.ShortName
    > rng.Offset(0, 2).Value = oCurrentFile.Path
    > rng.Offset(0, 3).Value = oCurrentFile.DateCreated
    > rng.Offset(0, 4).Value = oCurrentFile.DateLastAccessed
    > rng.Offset(0, 5).Value = oCurrentFile.DateLastModified
    > rng.Offset(0, 6).Value = oCurrentFile.Size
    > rng.Offset(0, 7).Value = oCurrentFile.Type
    > rng.Offset(0, 8).Value = oCurrentFile.Attributes
    > Set rng = rng.Offset(1, 0)
    > Next oCurrentFile
    > End Sub
    > '<<=============
    >
    >
    > ---
    > Regards,
    > Norman




  4. #4
    gilgil
    Guest

    Re: Getting a List of File Names

    Thank you very much. That is really what I am looking for.
    --
    gilgil259

    Antispam: replace 259 with 159



    "Norman Jones" <[email protected]> ha scritto nel messaggio
    news:%[email protected]...
    > Hi Gilgil,
    >
    > Try the following which was previously posted by Jim Thomlinson::
    > '=============>>
    > Sub ListFiles()




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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