Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Directory Contents

Jo,

The actual code will depend on what specifically you want to do
with the list. Try the following code to create a tree-like list
in an Excel worksheet.

Sub Start()

Const START_FOLDER_NAME = "H:\ExcelProjects" '<<< CHANGE
Dim FSO As Object
Dim Rng As Range
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Rng = Range("A1")
Rng.Value = START_FOLDER_NAME
Set Rng = Rng(2, 2)
ProcessOneFolder FSO.GetFolder(START_FOLDER_NAME), Rng

End Sub


Sub ProcessOneFolder(Fldr As Object, Rng As Range)

Dim OneFile As Object
Dim OneFolder As Object
For Each OneFile In Fldr.Files
Rng.Value = OneFile.Path
Set Rng = Rng(2, 1)
Next OneFile
For Each OneFolder In Fldr.SubFolders
Rng.Value = OneFolder.Path
Set Rng = Rng(2, 2)
ProcessOneFolder OneFolder, Rng
Set Rng = Rng(1, 0)
Next OneFolder

End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jo" wrote in message
...
Has anyone got any code to return a list of the contents of a

directory and its sub folders?

TIA



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
concatenate contents of cells whose contents resemble cell referem cathyh Excel Worksheet Functions 3 May 23rd 09 12:16 PM
Listing Directory Contents in Worksheet Pablo Excel Discussion (Misc queries) 2 August 2nd 05 06:09 PM
macro to move contents of directory Harvey[_3_] Excel Programming 0 February 9th 04 07:36 PM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM
Listing the contents of a directory in a spreadsheet Angelikoula Excel Programming 2 November 6th 03 01:44 PM


All times are GMT +1. The time now is 07:12 AM.

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"