Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default Listing the contents of a folder

I am looking to write a macro that will list the contents of a
specified folder, including the contents of subfolders. Is this
something that i can do with a macro?

Thanks.

Asa

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default Listing the contents of a folder

It would help if you mapped the folder that you want to list out to a drive.

I do this as follows:

Start - Run - cmd

I have multiple drives mapped. Let's say I want to get a listing of the Y
drive.

I type in Y:

I then type:

dir/s z:textfile.txt

It will save a listing of the Y drive on my Z drive as a file named
textfile.txt

Good luck.


" wrote:

I am looking to write a macro that will list the contents of a
specified folder, including the contents of subfolders. Is this
something that i can do with a macro?

Thanks.

Asa


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default Listing the contents of a folder


Change strPath to the desired folder.
Listing added to Column B of active sheet.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

Sub ListAllFilesInFolder()
'Jim Cone - San Francisco - Oct 2006
Dim strPath As String
Dim oFSO As Object
Dim oFile As Object
Dim oFolder As Object

Dim N As Long
N = 1
strPath = "C:\Documents and Settings\Name\My Documents\Excel Files"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strPath)
Cells(N, 1).Value = oFolder.Path
N = N + 1
For Each oFile In oFolder.Files
Cells(N, 2).Value = oFile.Name
N = N + 1
Next 'oFile
Call ListSubFolderFiles(oFolder, N)

Set oFSO = Nothing
Set oFile = Nothing
Set oFolder = Nothing
End Sub

Function ListSubFolderFiles(ByRef oParentFolder As Object, ByRef lngR As Long)
Dim oSubFolder As Object
Dim oFile As Object
For Each oSubFolder In oParentFolder.SubFolders
Cells(lngR, 1).Value = oSubFolder.Path
Range(Cells(lngR, 1), Cells(lngR, 5)).Interior.ColorIndex = 15
lngR = lngR + 1
For Each oFile In oSubFolder.Files
Cells(lngR, 2).Value = oFile.Name
lngR = lngR + 1
Next
ListSubFolderFiles oSubFolder, lngR
Next 'oSubFolder
End Function
'---------------



wrote in message
I am looking to write a macro that will list the contents of a
specified folder, including the contents of subfolders. Is this
something that i can do with a macro?
Thanks.
Asa

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
Followup: Folder listing [email protected] Excel Discussion (Misc queries) 1 February 23rd 07 02:23 AM
How can I insert the contents of a folder into Excel np Excel Discussion (Misc queries) 3 October 3rd 06 07:05 AM
add a folder to c:\ drive from cell A1 contents... [email protected] Excel Discussion (Misc queries) 1 July 25th 06 09:48 PM
Periodically listing files in a folder haven104 Excel Discussion (Misc queries) 2 January 10th 06 09:01 AM
Listing Directory Contents in Worksheet Pablo Excel Discussion (Misc queries) 2 August 2nd 05 06:09 PM


All times are GMT +1. The time now is 02:38 PM.

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

About Us

"It's about Microsoft Excel"