Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Retrieve File Names in Directories

Can anyone tell me how or if it is possible to start at a particular
directory and drill down to all subdirectories and get the names of files and
the associated paths of each? I was thinking you can do this with the File
System Object within Excel VBA?? If anyone could point me to good web site
that covers this, it would be appreciated.

I basically want to start at one directory and follow all paths until no
more directories. So drill both down and accross. Hopefully I am explaining
correctly.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Retrieve File Names in Directories

Hi SharonM,

What do you want to do with them after you get them?

Dan
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Retrieve File Names in Directories

At a minimum get a list in an Excel worksheet with the File name and Path.

But I also might need to rename one or more of the files if possible.

Thanks!


"dan dungan" wrote:

Hi SharonM,

What do you want to do with them after you get them?

Dan
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Retrieve File Names in Directories

Recursion and the FSO, courtesy of Chip Pearson:
http://www.cpearson.com/EXCEL/RecursionAndFSO.htm

I also have full working code that pretty much does what your asking for. I
think it's based on Chip's code, but I'm not certain (I didn't write down the
original source when I stole it <g before modifying it). If you'd like a
sample workbook with my code in it, get in touch via email to (remove spaces)
HelpFrom @ JLatham Site. com


"sharonm" wrote:

At a minimum get a list in an Excel worksheet with the File name and Path.

But I also might need to rename one or more of the files if possible.

Thanks!


"dan dungan" wrote:

Hi SharonM,

What do you want to do with them after you get them?

Dan
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Retrieve File Names in Directories

Here's some code I posted a while ago. Change the values marked with
'<<< to meet your needs and then run the StartHere procedure.
StartFolderName is the fully qualified name of the folder whose
contents you want to list. Indent indicates whether subdirectories and
file should be indented from their parent folder. ListFiles indicates
whether to list files in addition to folders. R is the range address
at which the listing is to begin. See also
http://www.cpearson.com/Excel/FolderTree.aspx and
http://www.cpearson.com/Excel/FolderTreeView.aspx and
http://www.cpearson.com/Excel/RecursionAndFSO.htm


Sub StartHere()
Dim FSO As Scripting.FileSystemObject
Dim StartFolderName As String
Dim StartFolder As Scripting.Folder
Dim F As Scripting.File
Dim SubF As Scripting.Folder
Dim R As Range
Dim Indent As Boolean
Dim ListFiles As Boolean
Set FSO = New Scripting.FileSystemObject

StartFolderName = "C:\Utilica" ' <<< Start Folder
Indent = True '<<< Indent listing
ListFiles = False '<<< List file names
Set R = Range("A1") '<<< List start cell

Set StartFolder = FSO.GetFolder(StartFolderName)
ListSubFoldersAndFiles FSO, StartFolder, R, Indent, ListFiles

End Sub

Sub ListSubFoldersAndFiles(FSO As Scripting.FileSystemObject, _
FF As Scripting.Folder, _
R As Range, _
Indent As Boolean, ListFiles As Boolean)

Dim SubF As Scripting.Folder
Dim F As Scripting.File
R.Value = FF.Path
For Each SubF In FF.SubFolders
Set R = R(2, 1)
If Indent = True Then
Set R = R(1, 2)
End If
ListSubFoldersAndFiles FSO, SubF, _
R, Indent, ListFiles
If Indent = True Then
Set R = R(1, 0)
End If
Next SubF

If ListFiles = True Then
If Indent = True Then
Set R = R(1, 2)
End If
For Each F In FF.Files
Set R = R(2, 1)
R.Value = F.Name
Next F
If Indent = True Then
Set R = R(1, 0)
End If
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Thu, 4 Mar 2010 10:49:05 -0800, sharonm
wrote:

Can anyone tell me how or if it is possible to start at a particular
directory and drill down to all subdirectories and get the names of files and
the associated paths of each? I was thinking you can do this with the File
System Object within Excel VBA?? If anyone could point me to good web site
that covers this, it would be appreciated.

I basically want to start at one directory and follow all paths until no
more directories. So drill both down and accross. Hopefully I am explaining
correctly.

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
Changing file/open and file/saveas directories jamjam Excel Programming 1 November 30th 07 04:48 PM
How to retrieve procedures ans functions names in VBA ? Aeronav[_2_] Excel Programming 1 August 31st 07 10:43 AM
Macro to save file in changing directories? [email protected] Excel Programming 2 April 18th 07 06:24 PM
File Open doesn't display all directories (List vs Details) OakCity Excel Discussion (Misc queries) 4 September 2nd 05 01:40 AM
Reference names and hyperlinks to other files in other directories Brains[_2_] Excel Programming 0 February 4th 04 02:01 PM


All times are GMT +1. The time now is 08:37 AM.

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"