Ashutosh Jog wrote:
> 
> Hello all,

Hello,

> I am a complete newbie and am trying to do a couple of things but was
> not able to. Any assitance is welcome.
> 
>  If I have a dir structure G:\abc\efg\qrs.txt:
> 
>  1) How can I list the entire structure under G:\abc along with all the dirs.
> under G:\abc\ right upto the file qrs.txt ?

Use the File::Find module to tranverse an entire directory tree.


>     In this structure the dir name abc will not change and neither will the
> name of the file qrs.txt. But there will be a     different dir name for efg
> for eg: there will be dirs as under
> G:\abc\efg\qrs.txt
> G:\abc\hij\qrs.txt .......etc. etc.
> 
> How can I have these listed in a file (line by line) using perl?
> 
>  2) Then I would want to take the individual dir names under G:\abc and
>  put them in a separate txt file.
>      For eg: From the above eg., I would like to have the dir's 'efg' and
>  'hij' listed in a diff txt file, line by line (i.e just these dir name)
> 
>  Is there a way to do so in perl? I could do the first part in shell
>  script but wasn't sure how it would work under perl. Thank you in
>  advance for your patience.


#!/usr/bin/perl
use warnings;
use strict;

my $dir  = 'G:/abc';
my $file = 'qrs.txt';
my $out1 = 'list.txt';
my $out2 = 'dirs.txt';


open LIST1, '>', $out1 or die "Cannot open $out1: $!";
open LIST2, '>', $out2 or die "Cannot open $out2: $!";

opendir DIR, $dir or die "Cannot opendir $dir: $!";

while ( defined( my $ent = readdir DIR ) ) {
    if ( -e "$dir/$ent/$file" ) {
        print LIST1 "$dir/$ent/$file\n";
        }
    if ( -d "$dir/$ent" ) {
        print LIST2 "$ent\n";
        }
    }

__END__




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to