newlearner has asked for the wisdom of the Perl Monks concerning the following question:
I have a directory structure like shown below
----------------------------------------------------------------------------------------------------Directory: /proj/newdata/ Files: alpha.seq, beta.pm, gamma.txt Sub Directories: dog, cat Sub-Directory:dog Files: batman0.seq, batman1.txt Sub Directories: D1, D2 Sub-Directory: D1 Files: joker0.seq, joker1.pm Sub Directories: C0 Sub-Directory: C0 Files: file0.seq, file1.pm, file.txt Sub-Directory:cat Files: man0.seq, man1.txt Sub Directories: D3, D4 Sub-Directory: D3 Files: jok0.seq, jok1.pm Sub Directories: C1 Sub-Directory: C1 Files: f0.seq, f1.pm, f.txt
Now I want a perl script which can take the input directory name '/proj/newdata' and find all the files that end only with .seq and .pm and print them according to their directory structure like this:
RESULT: -------------------------------------------------
Group: /proj/newdata { File: alpha.seq (/proj/newdata/alpha.seq) File: beta.pm (/proj/newdata/beta.pm) Group: dog { File: batman0.seq (/proj/newdata/dog/batman0.seq) Group: D1 { File: joker0.seq (/proj/newdata/dog/D1/joker0.seq) File: joker1.pm (/proj/newdata/dog/D1/joker1.pm) Group: C0 { File: file0.seq (/proj/newdata/dog/D1/C0/file0.seq) File: file11.pm (/proj/newdata/dog/D1/C0/file1.pm) } #Group C0 } # Group D1 } # Group Dog Group: cat { File: man0.seq (/proj/newdata/cat/man0.seq) Group: D3 { File: jok0.seq (/proj/newdata/cat/D3/jok0.seq) File: jok1.pm (/proj/newdata/cat/D3/jok1.pm) Group: C1 { File: f0.seq (/proj/newdata/dog/D3/C1/file0.seq) File: f1.pm (/proj/newdata/dog/D3/C1/file1.pm) } #Group C1 } # Group D3 } # Group Cat } # Group /proj/newdata
-------------------------------------------------------
The words after "#" are comments and are not required.
Any help would be appreciated. I used File::Find and some other ways but could not crack the correct directory structuring printing and it's been some time I am working on this.
Thankyou
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Traverse through directory structure and print in required format
by GrandFather (Saint) on Mar 14, 2011 at 23:03 UTC | |
|
Re: Traverse through directory structure and print in required format
by Anonymous Monk on Mar 14, 2011 at 22:58 UTC | |
|
Re: Traverse through directory structure and print in required format
by ikegami (Patriarch) on Mar 14, 2011 at 23:05 UTC | |
by ikegami (Patriarch) on Mar 14, 2011 at 23:13 UTC |