Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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 --> file1.xyz file2.asd 1abc --> CIT+B+200.xyz CIT+B+200.asd 2def --> ISU+A+300.xyz ISU+A+300.asd 3ijk --> CNC+C+400.xyz 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 (Abbot) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://956592]
Approved by moritz
help
Chatterbox?
[ambrus]: Petroza had trouble posting yesterday, but has posted Issues Fetching URL with a variable token since.
[mz2255]: Yes, just edited the scratchpad. Not sure if I'm doing something wrong, it's my first time.
[ambrus]: No, you're not doing anything wrong. It's just that our automatic spam filters confuse you with the spammers who post advertisments for online shops of counterfeit branded clothing.
[ambrus]: Or unless you left the title field empty or entered a very short title for the node, but then you'd get a message saying that.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2017-10-19 15:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (255 votes). Check out past polls.

    Notices?