Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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()



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a list using the file names Garry Excel Discussion (Misc queries) 1 April 12th 10 03:53 PM
how do I import a list of music file names into excel davydahl Excel Discussion (Misc queries) 5 April 13th 08 05:04 PM
How to create a list of file names within a folder in Microsoft Ex Seablue Excel Discussion (Misc queries) 2 April 9th 07 08:44 PM
how can you list all of the worksheet names in a file harish Excel Discussion (Misc queries) 1 March 6th 06 04:13 PM
need to copy a long list of file names gilcola Excel Discussion (Misc queries) 6 August 19th 05 12:55 AM


All times are GMT +1. The time now is 03:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"