Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deep Directory Listings

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I have a directory with several levels of sub directories under it. These go down to a level of 4 or 5 in some cases.
I want to create a list of all the directories in the entire tree.

I have been looking at file::find but I don't think it is what I am looking for as it only seems to go down one level.
Is there a module which does a deep directory listing or do I need to roll my own?



Keith
 
Hi

Mine goes deep enough :
Code:
[b]use[/b] File[teal]::[/teal]Find[teal];[/teal]

[b]my[/b] [navy]$max[/navy] [teal]=[/teal] [purple]0[/purple][teal];[/teal]
[b]my[/b] [navy]$longest[/navy] [teal]=[/teal] [i][green]''[/green][/i][teal];[/teal]

File[teal]::[/teal]Find[teal]::[/teal][COLOR=orange]find[/color][teal]([/teal][b]sub[/b] [teal]{[/teal]
    [navy]$depth[/navy] [teal]=[/teal] scalar @[teal]{[[/teal][navy]$File[/navy][teal]::[/teal]Find[teal]::[/teal]name [teal]=~[/teal] [b]m[/b][teal],/,[/teal][b]g[/b][teal]]};[/teal]
    [b]if[/b] [teal]([/teal][navy]$max[/navy] [teal]<[/teal] [navy]$depth[/navy][teal]) {[/teal]
        [navy]$max[/navy] [teal]=[/teal] [navy]$depth[/navy][teal];[/teal]
        [navy]$longest[/navy] [teal]=[/teal] [navy]$File[/navy][teal]::[/teal]Find[teal]::[/teal]name[teal];[/teal]
    [teal]}[/teal]
[teal]},[/teal] [i][green]'/'[/green][/i][teal]);[/teal]

[b]print[/b] [green][i]"
max        : $max
longest    : $longest
Perl       : $]
File::Find : $File::Find::VERSION
"[/i][/green][teal];[/teal]
Code:
[blue]master #[/blue] perl Keith.pl
max        : 23
longest    : /home/master/.gradle/wrapper/dists/gradle-2.2.1-all/6dibv5rcnnqlfbq9klf8imrndn/gradle-2.2.1/samples/userguide/multiproject/dependencies/java/services/personService/src/test/java/org/gradle/sample/services/PersonServiceTest.java
Perl       : 5.022002
File::Find : 1.29

Sure the problem is not somewhere else ?

Feherke.
feherke.ga
 
Thanks
The gateway just timed out on me so I am not sure what the script just did.

I have been looking at examples of File::Find and they all just go down one level.
I will have a look at it again.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top