View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JulieD JulieD is offline
external usenet poster
 
Posts: 618
Default How to Get Folder Names

Hi GC

there's probably a better way, as this will only work on files that are in a
subdirectory directly under I:\New Songs\
but you could give it a try
-----
Sub IndexFiles()
With Application.FileSearch
..NewSearch
..LookIn = "I:\New Songs"
..SearchSubFolders = True
..Filename = "*.xls"
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
fname2 = Application.FileSearch.FoundFiles.Item(i)
fname = Mid(fname2, InStr(4, fname2, "\") + 1, InStr(9, fname2, "\") -
InStr(4, fname2, "\") - 1)
Rng = "A" & i
Range(Rng).Value = fname
Next
End If
End With
End Sub
---
hope this helps
Cheers
julieD

"GC." wrote in message
...

Dear Helpers,

First of all I would like to thank you so very much for some help that
I got from this site...

I was searching for keywords "extract file names from folders" and I
got many results but went with 'this page' (http://tinyurl.com/4gk7n).
And the modified code post from VIKRAM...just did what I wanted to
do...here'z the CODE:

============================
Sub IndexFiles()
With Application.FileSearch
LookIn = "C:\MyMusic"
FileType = msoFileTypeAllFiles
SearchSubFolders = True
Execute
End With
cnt = Application.FileSearch.FoundFiles.Count
For i = 1 To cnt
Rng = "A" & i
Range(Rng).Value = Application.FileSearch.FoundFiles.Item(i)
Next i
End Sub
=============================

Now...here'z a little additional stuff that I would like Excel to
perform...

After making this macro as guided by Vikram in the above hyperlink, I
am able to get the path to all files...like this:

I:\New Songs\DAP Songs\(AA_AB_LAUT_CHALEN)-MERA_DIL_TERA_DEEWANA.mp3
I:\New Songs\DAP Songs\(DIL_SE)-DILSERE_DILSERE.mp3
I:\New Songs\BEST OF STERIO NATION\01 - ISHQ HOGAYA.mp3
I:\New Songs\NAYEE PADOSAN\01 - SARI SARI RAINA.mp3
I:\New Songs\Aashiqui - Abhijeet\01 - Track 1.rmj

Now what exactly I wanna do is to get the names of the Folders (ONLY,
as highlighted in red colour in the above lines) instead of
files...like I want instead of above five lines...

DAP Songs
Best of STERIO NATION
NAYEE PADOSAN
Aashiqui - Abhijeet

NB: As DAP Songs has two files in it, so it appeared twice in the above
list...but since it is only one directory, I want it in my list once
only...

Hope to receive help ASAP :) THANK YOU GUYz once again in advance for
any help.

Kind regards.

GC.


--
GC.
------------------------------------------------------------------------
GC.'s Profile:
http://www.excelforum.com/member.php...o&userid=16652
View this thread: http://www.excelforum.com/showthread...hreadid=318633