#1   Report Post  
SS
 
Posts: n/a
Default List folders to file

Hi

Does anyone have a macro that would list all the folders (with path) and
subfolders to an excel sheet but not the files?

Thanks
Shona


  #2   Report Post  
Dave O
 
Posts: n/a
Default

Shona-
There's a function called CELL() that should return your filename (or
any of a number of parameters) but I can't get it to work properly on
my machine, so I can't make it work for you. The syntax is
=CELL("filename") which ought to return the path and filename of the
current file, and which you could then trim down to show just the path.

Can anyone provide some guidance here?

  #3   Report Post  
Steve Yandl
 
Posts: n/a
Default

Dave,

If it isn't working for you, it probably means that you've not saved the
file yet.

I read Shona's question a bit differently. I think the goal is to populate
a worksheet with the folder structure of some drive, similar to a Windows
Explorer type display without listing files.

Steve


"Dave O" wrote in message
ups.com...
Shona-
There's a function called CELL() that should return your filename (or
any of a number of parameters) but I can't get it to work properly on
my machine, so I can't make it work for you. The syntax is
=CELL("filename") which ought to return the path and filename of the
current file, and which you could then trim down to show just the path.

Can anyone provide some guidance here?



  #4   Report Post  
Dave O
 
Posts: n/a
Default

Thanks, Steve, you were right about not saving the file.

I looked into the DIR function in VB Help, which indicates that DIR may
not be called recursively. So I'm fresh out of answers.

  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

One way:

Option Explicit
Dim myRow As Long
Dim wks As Worksheet
Sub testme()
Set wks = Worksheets.Add
myRow = 0
Call FoldersInFolder("C:\my documents") '<-- change this
End Sub
Sub FoldersInFolder(myFolderName As String)

' Dim FSO As Scripting.FileSystemObject
' Dim myBaseFolder As Scripting.Folder
' Dim myFolder As Scripting.Folder
' Set FSO = New Scripting.FileSystemObject

Dim FSO As Object
Dim myBaseFolder As Object
Dim myFolder As Object
Set FSO = CreateObject("scripting.filesystemobject")

Set myBaseFolder = FSO.GetFolder(myFolderName)

For Each myFolder In myBaseFolder.SubFolders
myRow = myRow + 1
wks.Cells(myRow, "A").Value = myFolder.Path
Call FoldersInFolder(myFolder.Path)
Next myFolder

End Sub

I commented out some specific Dim statements. If you want to use those (instead
of the As Object lines), you'll have to set a reference to "microsoft scripting
library" via tools|References.

Using the references makes coding/debugging easier--you get that nice
intellisense feature from the VBE.

SS wrote:

Hi

Does anyone have a macro that would list all the folders (with path) and
subfolders to an excel sheet but not the files?

Thanks
Shona


--

Dave Peterson


  #6   Report Post  
SS
 
Posts: n/a
Default

Thanks for that but it stops at

Set myBaseFolder = FSO.GetFolder(myFolderName)

Shona


  #7   Report Post  
SS
 
Posts: n/a
Default

Forget that thanks my mistake put the path wrong!

Thanks again this is great
"SS" wrote in message
...
Thanks for that but it stops at

Set myBaseFolder = FSO.GetFolder(myFolderName)

Shona




  #8   Report Post  
Member
 
Location: London
Posts: 78
Default

Dave,

That's great - I've been looking for a way to do this for a long time too (I have been wanting to write a routine which recurses through a chunk of folders and print all the files in each one *in order* - all that remains now is seeing if I can access the standard Windows 'File - Print' function or DDE message using SHELL or some such).

Does anybody else dread trying to find out the methods and properties available in the Scripting.FileSystemObject? I've never found a way to browse the methods of referenced objects or display help on them.

Is there a way, or is it in some optional help file that's not included in Typical Install? Or does it entail buying an expensive reference book from Microsoft Press?

BizMark
  #9   Report Post  
Dave Peterson
 
Posts: n/a
Default

There's lots of free info at MS.

VBScript User's Guide
http://msdn.microsoft.com/scripting/...c/vbstutor.htm
http://msdn.microsoft.com/scripting/...oad/vbsdoc.exe
http://msdn.microsoft.com/scripting/...load/jsdoc.exe
http://msdn.microsoft.com/scripting/...ost/wshdoc.exe
http://msdn.microsoft.com/scripting/...ets/wscdoc.exe

(saved from a long time ago.)

And from another post I've kept:

WSH 2.0 Tutorial
http://msdn.microsoft.com/scripting/...utorialTOC.htm
WSH Documentation
http://msdn.microsoft.com/scripting/...ce/default.htm
http://msdn.microsoft.com/scripting/...ost/wshdoc.exe

VBScript User's Guide
http://msdn.microsoft.com/scripting/...c/vbstutor.htm
VBScript Documentation
http://msdn.microsoft.com/scripting/...fo/vbsdocs.htm
http://msdn.microsoft.com/scripting/...oad/vbsdoc.exe

FileSystemObject User's Guide
http://msdn.microsoft.com/scripting/...jsFSOTutor.htm
VBScript Run-Time Library Reference [FileSystemObject/Dictionary]
http://msdn.microsoft.com/scripting/.../VBSFSOTOC.htm

JScript User's Guide
http://msdn.microsoft.com/scripting/...UsersGuide.htm
JScript Documentation
http://msdn.microsoft.com/scripting/...nfo/jsdocs.htm
http://msdn.microsoft.com/scripting/...load/jsdoc.exe

WSC Tutorial
http://msdn.microsoft.com/scripting/...c/lettitle.htm
WSC Documentation
http://msdn.microsoft.com/scripting/...serverdocs.htm
http://msdn.microsoft.com/scripting/...ets/wscdoc.exe


In fact, there are newsgroups that are devoted to scripting. You could search
google for common questions and post questions when you can't find answers.


BizMark wrote:

Dave,

That's great - I've been looking for a way to do this for a long time
too (I have been wanting to write a routine which recurses through a
chunk of folders and print all the files in each one *in order* - all
that remains now is seeing if I can access the standard Windows 'File -
Print' function or DDE message using SHELL or some such).

Does anybody else dread trying to find out the methods and properties
available in the Scripting.FileSystemObject? I've never found a way to
browse the methods of referenced objects or display help on them.

Is there a way, or is it in some optional help file that's not included
in Typical Install? Or does it entail buying an expensive reference
book from Microsoft Press?

BizMark

--
BizMark


--

Dave Peterson
  #10   Report Post  
TommySzalapski
 
Posts: n/a
Default


Wow, guys, just use the DOS command prompt.

from the C:\ prompt

dir/s/b directory.txt 'This will put all the folders and filenames in
a txt file (which Excel reads just fine)
dir/s/b/ad directory.txt 'This will send just the folders and not the
filenames.
Type dir /? for even more options.
A single overwrites anything that is in the file.
A double appends the new data to the end of the file (directory.txt
is just an arbitrary file name you can call it anything you want)

Sure this is not done from excel, but it is much simpler.

Szalapski


--
TommySzalapski
------------------------------------------------------------------------
TommySzalapski's Profile: http://www.excelforum.com/member.php...o&userid=25561
View this thread: http://www.excelforum.com/showthread...hreadid=394981



  #11   Report Post  
Dave Peterson
 
Posts: n/a
Default

I think "simpler" depends on how often you have to do it and who's gonna do the
work. And if it's part of a larger mechanized routine, then you'd have to
start, stop, do manual effort and restart.

Once you set up the macro, you could be done--just rerun it when you want.

You won't have to get to the command prompt or import the data.

TommySzalapski wrote:

Wow, guys, just use the DOS command prompt.

from the C:\ prompt

dir/s/b directory.txt 'This will put all the folders and filenames in
a txt file (which Excel reads just fine)
dir/s/b/ad directory.txt 'This will send just the folders and not the
filenames.
Type dir /? for even more options.
A single overwrites anything that is in the file.
A double appends the new data to the end of the file (directory.txt
is just an arbitrary file name you can call it anything you want)

Sure this is not done from excel, but it is much simpler.

Szalapski

--
TommySzalapski
------------------------------------------------------------------------
TommySzalapski's Profile: http://www.excelforum.com/member.php...o&userid=25561
View this thread: http://www.excelforum.com/showthread...hreadid=394981


--

Dave Peterson
  #12   Report Post  
Member
 
Location: London
Posts: 78
Default

Quote:
Originally Posted by TommySzalapski
Wow, guys, just use the DOS command prompt.

from the C:\ prompt

dir/s/b directory.txt 'This will put all the folders and filenames in
a txt file (which Excel reads just fine)
dir/s/b/ad directory.txt 'This will send just the folders and not the
filenames.
Type dir /? for even more options.
A single overwrites anything that is in the file.
A double appends the new data to the end of the file (directory.txt
is just an arbitrary file name you can call it anything you want)

Sure this is not done from excel, but it is much simpler.

Szalapski


--
TommySzalapski
------------------------------------------------------------------------
TommySzalapski's Profile: http://www.excelforum.com/member.php...o&userid=25561
View this thread: http://www.excelforum.com/showthread...hreadid=394981

I think the point was, Tommy, that a method was needed that IS done from Excel!!!

BM
  #13   Report Post  
Dodo
 
Posts: n/a
Default

Dave Peterson wrote in
:

One way:



SS wrote:

Hi

Does anyone have a macro that would list all the folders (with path)
and subfolders to an excel sheet but not the files?


Another way would be through the ASAP utilities:

http://www.asap-utilities.com/

Import/Insert files

Oops! That's just doing the filenames.
Anyhow, plenty of useful additions, isn't it?


--

It is I, DeauDeau
(Free after monsieur Leclerc in 'Allo, 'allo)
  #14   Report Post  
TommySzalapski
 
Posts: n/a
Default


Alright, use (in Excel) the VBA command SHELL. You can then run the
command prompt script from excel and have the best of both worlds.

Szalapski


--
TommySzalapski
------------------------------------------------------------------------
TommySzalapski's Profile: http://www.excelforum.com/member.php...o&userid=25561
View this thread: http://www.excelforum.com/showthread...hreadid=394981

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
Excel updating from XML file - file path specific? Sean Excel Discussion (Misc queries) 4 August 5th 05 12:56 PM
.txt file to mail list (excel best option) Zeagle New Users to Excel 1 June 30th 05 07:31 AM
how do i import a file list in to excel liam Excel Discussion (Misc queries) 1 June 25th 05 11:16 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 0 February 19th 05 02:03 PM
Extracting Values on one list and not another B Schwarz Excel Discussion (Misc queries) 4 January 7th 05 01:48 PM


All times are GMT +1. The time now is 01:37 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"