![]() |
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 |
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" wrote in message ... 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 |
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" wrote in message ... 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 |
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" ha scritto nel messaggio ... Hi Gilgil, Try the following which was previously posted by Jim Thomlinson:: '============= Sub ListFiles() |
All times are GMT +1. The time now is 12:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com