For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2005 > File::Find question?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author File::Find question?
S E

2005-03-29, 8:56 pm

Hello!

I have been working on familiarizing myself with the File::Find module. We have a process that appends a .txt once it has processed the file in a Unix environment. So, I wanted to return a list of files that have been processed by the previous process.
I have been using the below to achieve that.

Here is my question which I have been having problems with. I want to create a list of the files that have not been processed. But, due to the naming conventions (or lack of) the only way to find those find the files that have not been processed is to l
ook for files without a .txt in the file name. Is there a modification that I can make to the below to achieve that?

Thanks,
S

--

#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
find (\&match_pattern, "/home/user/prod" );
sub match_pattern {
print "$File::Find::name\n" if ( m/txt/ );
}


--

Wagner, David --- Senior Programmer Analyst --- WG

2005-03-29, 8:56 pm

S E wrote:
> Hello!
>=20
> I have been working on familiarizing myself with the File::Find
> module. We have a process that appends a .txt once it has processed
> the file in a Unix environment. So, I wanted to return a list of
> files that have been processed by the previous process. I have been
> using the below to achieve that. =20
>=20
> Here is my question which I have been having problems with. I want
> to create a list of the files that have not been processed. But, due
> to the naming conventions (or lack of) the only way to find those
> find the files that have not been processed is to look for files
> without a .txt in the file name. Is there a modification that I can
> make to the below to achieve that? =20
>=20
> Thanks,
> S
>=20
> --
>=20
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Find;

my @MyUnProcssed =3D ();

> find (\&match_pattern, "/home/user/prod" );
> sub match_pattern {
> print "$File::Find::name\n" if ( m/txt/ );

if ( m/\.txt$/ ) { # so if you have file txt1 it will not find it, but doe=
s find txt1.txt
print "$File::Find::name\n" =09
}else {
push(@MyUnProcessed, $File::Find::name);
}

One way.
Wags ;)
> }
>=20
>=20
> --




****************************************
***************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************
***************

John W. Krahn

2005-03-29, 8:56 pm

S E wrote:
> Hello!


Hello,

> I have been working on familiarizing myself with the File::Find module. We
> have a process that appends a .txt once it has processed the file in a Unix
> environment. So, I wanted to return a list of files that have been
> processed by the previous process. I have been using the below to achieve
> that.
>
> Here is my question which I have been having problems with. I want to
> create a list of the files that have not been processed. But, due to the
> naming conventions (or lack of) the only way to find those find the files
> that have not been processed is to look for files without a .txt in the
> file name. Is there a modification that I can make to the below to achieve
> that?
>
> --
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use File::Find;
> find (\&match_pattern, "/home/user/prod" );
> sub match_pattern {
> print "$File::Find::name\n" if ( m/txt/ );
> }



#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
my ( @processed, @not_processed );
find( sub {
push @{ /\.txt$/ ? \@processed : \@not_processed }, $File::Find::name;
}, '/home/user/prod' );
print map "$_\n", @processed;




John
--
use Perl;
program
fulfillment
Steven Schubiger

2005-03-29, 8:56 pm

On 29 Mar, S E wrote:

> But, due to the naming conventions (or lack of) the only way to find
> those find the files that have not been processed is to look for files
> without a .txt in the file name. Is there a modification that I can
> make to the below to achieve that?


> print "$File::Find::name\n" if ( m/txt/ );


print $File::Find::name, "\n" unless /\.txt^/;

--
Steven Schubiger
<steven@accognoscere.org>
Offer Kaye

2005-03-30, 3:56 pm

On Tue, 29 Mar 2005 23:31:48 +0200 (CEST), Steven Schubiger wrote:
>
> print $File::Find::name, "\n" unless /\.txt^/;
>


No, that should be /\.txt$/ , not /\.txt^/ - you're using the wrong anchor.

--
Offer Kaye
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com