Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default List folders but not sub folders

Hello all

I am trying to list the folders in a path but not the sub folders.
For example, if i have c:\test\ with folders F1, F2, F3 in it, and in
folder F3 is folder F3.1 i want the output (in excel worksheet) to be

c:\test\f1
c:\test\f2
c:\test\f3

and not have ctest\f3.1 listed as a folder

I have used the code below from this forum - any advice how to amend
it?

Thanks

Set a reference (in VBA, Tools menu, References item) to
Microsoft Scripting Library and use code like the following:


Sub Start()
Dim FSO As Scripting.FileSystemObject
Dim TopFolder As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set TopFolder = FSO.GetFolder("C:\Temp")
DoOneFolder TopFolder
End Sub


Sub DoOneFolder(F As Scripting.Folder)
Dim OneFolder As Scripting.Folder
'
' do something with F
Debug.Print F.Path


For Each OneFolder In F.SubFolders
DoOneFolder OneFolder
Next OneFolder
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default List folders but not sub folders

just eliminate the recursive call

Delete these 3 lines
For Each OneFolder In F.SubFolders
DoOneFolder OneFolder
Next OneFolder


"kaiser" wrote:

Hello all

I am trying to list the folders in a path but not the sub folders.
For example, if i have c:\test\ with folders F1, F2, F3 in it, and in
folder F3 is folder F3.1 i want the output (in excel worksheet) to be

c:\test\f1
c:\test\f2
c:\test\f3

and not have ctest\f3.1 listed as a folder

I have used the code below from this forum - any advice how to amend
it?

Thanks

Set a reference (in VBA, Tools menu, References item) to
Microsoft Scripting Library and use code like the following:


Sub Start()
Dim FSO As Scripting.FileSystemObject
Dim TopFolder As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set TopFolder = FSO.GetFolder("C:\Temp")
DoOneFolder TopFolder
End Sub


Sub DoOneFolder(F As Scripting.Folder)
Dim OneFolder As Scripting.Folder
'
' do something with F
Debug.Print F.Path


For Each OneFolder In F.SubFolders
DoOneFolder OneFolder
Next OneFolder
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default List folders but not sub folders

Hi

Here is an UDF I use to get n-th subfolder from a specified folder. (The UDF
is meant to use as Excel worksheet function, the parameter MyTime allows to
turn the funtion volatile at will.) Probably

Public Function GetSubfolder(MyFolder As String, FolderNum As Integer,
Optional MyTime As Date)
Dim fs, f, f1, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(MyFolder)
Set sf = f.SubFolders
i = 0
For Each f1 In sf
i = i + 1
If i = FolderNum Then GetSubfolder = f1.Name
Next
End Function


--
Arvi Laanemets
( My real mail address: arvi.laanemets<attarkon.ee )


"kaiser" wrote in message
oups.com...
Hello all

I am trying to list the folders in a path but not the sub folders.
For example, if i have c:\test\ with folders F1, F2, F3 in it, and in
folder F3 is folder F3.1 i want the output (in excel worksheet) to be

c:\test\f1
c:\test\f2
c:\test\f3

and not have ctest\f3.1 listed as a folder

I have used the code below from this forum - any advice how to amend
it?

Thanks

Set a reference (in VBA, Tools menu, References item) to
Microsoft Scripting Library and use code like the following:


Sub Start()
Dim FSO As Scripting.FileSystemObject
Dim TopFolder As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set TopFolder = FSO.GetFolder("C:\Temp")
DoOneFolder TopFolder
End Sub


Sub DoOneFolder(F As Scripting.Folder)
Dim OneFolder As Scripting.Folder
'
' do something with F
Debug.Print F.Path


For Each OneFolder In F.SubFolders
DoOneFolder OneFolder
Next OneFolder
End Sub



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 List From Folders Don Excel Programming 12 August 11th 06 12:47 AM
List of Folders marianne Excel Programming 10 June 7th 06 11:48 AM
List Folders using Excel Andibevan[_4_] Excel Programming 3 December 15th 05 09:44 AM
List folders to file SS Excel Discussion (Misc queries) 13 August 28th 05 07:44 PM
Get folders list Eugene[_5_] Excel Programming 1 December 10th 03 10:44 AM


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