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
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
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
>
>
>
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
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()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks