Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2016-10-22 00:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.