Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

recursive directory navigation

by anasuya (Novice)
on Feb 28, 2012 at 06:50 UTC ( #956592=perlquestion: print w/replies, xml ) Need Help??
anasuya has asked for the wisdom of the Perl Monks concerning the following question:

I have a directory with multiple folders. Each folder has 2 files. So, the directory looks like this:
FORMAT: foldername --> file2.asd 1abc --> CIT+B+200.asd 2def --> ISU+A+300.asd 3ijk --> CNC+C+400.asd . . . . . .
I need to know how to navigate through each of these folders and get the names of the two files in it. Program should output the parsed filenames, and write them into a text file such that the text file looks like this:
1abc CIT B 200 2def ISU A 300 3ijk CNC C 400 . . . . .
- Thnks

Replies are listed 'Best First'.
Re: recursive directory navigation
by moritz (Cardinal) on Feb 28, 2012 at 07:14 UTC
Re: recursive directory navigation
by Anonymous Monk on Feb 28, 2012 at 07:07 UTC
Re: recursive directory navigation
by JavaFan (Canon) on Feb 28, 2012 at 07:26 UTC
    This works for me:
    ls -1 */*.xyz | sed -e 's![/+]! !g' -e 's!\.xyz$!!' > text-file
Re: recursive directory navigation
by Marshall (Monsignor) on Feb 28, 2012 at 14:16 UTC
    update: I now realize that the file format for the files is special...
    Since these file names come in regular pairs, I guess you could just key off of the .asd file...
    #!/usr/bin/perl -w use strict; use File::Find; use File::Basename; my @dirs = ('C:/temp/testing'); find (\&wanted, @dirs); sub wanted { if (-f and /^(\w+)\+(\w+)\+(\d+)\.asd/) { print basename($File::Find::dir,()),"\t$1 $2 $3\n"; } } #prints on my testing setup #abc1 CIT B 200 #def2 ISU A 300

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://956592]
Approved by moritz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-02-23 05:20 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (339 votes). Check out past polls.