http://www.perlmonks.org?node_id=956592

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 (Canon) 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