Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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

Comment on recursive directory navigation
Select or Download Code
Re: recursive directory navigation
by Anonymous Monk on Feb 28, 2012 at 07:07 UTC
Re: recursive directory navigation
by moritz (Cardinal) on Feb 28, 2012 at 07:14 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 (Prior) 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-09-30 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (363 votes), past polls