Home > Archive > PERL Beginners > June 2006 > Odd glob behavior
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]
|
|
| ercdvs@gmail.com 2006-06-27, 6:57 pm |
| In my program, I need to pull certian groupings of files and perform
various operations on them...
I first call :
use File::Copy;
use File::Find;
use File::Path;
use Time::localtime;
my $sourcedir = "//server/incoming/dir/PROD/";
my $workingdir = "c:/local/dir/";
chdir $sourcedir;
my $dateStamp = sprintf("%04d%02d%02d",
(localtime->year+1900),(localtime->mon+1),localtime->mday);
my @files = < *PendingTrades$dateStamp*.txt.pgp ) || warn("No Files
actually found $!");
foreach(@files)
{
print "Moving ==> $_\n";
move($_,$workingdir) || handleError ("Move Failed : $!\n");
}
The above fails ... it returns only the first file out of any number
of valid results.. even with NO results, @files still returns '1' .. no
matter if I even specify "*"
The following code set to work on the gatherd files is perfectly file
chdir $workingdir;
@files = < PendingTrades*.txt >;
foreach(@files)
{
print "Working ==> $_\n";
system("pgp +force -e \"".$_."\" \"xxxxxxx\""); # Encrypt File using
public key
move($_,$arch) || handleError ("Archive Failed : $!\n"); # move to
archive dir
&put($_.".pgp"); ## Send via FTP
}
all parts of this snippet work correctly, calling my various
subroutines... and I get a valid list of files to operate on.. I need
to chdir due to my windows paths having spaces..
The first part above seems to only return a proper result set if I use
:
opendir(D, $sourcedir);
my @files = grep {/PendingTrades$dateStamp/} readdir(D);
closedir(D);
Is this a quirk of activeperl on windows and remote UNC paths ??
| |
| saroo.maini@gmail.com 2006-06-27, 6:57 pm |
| hi,
To retrieve certain files from the directory use the module use
File::Find::Rule::Type. This module you can find in CPAN. and then use
this command:
my @files =
File::Find::Rule->file()->name('*.txt')->in($directory_path);
foreach my $fname(sort(@files))
{
print "file: $fname \n";
}
ercdvs@gmail.com wrote:
> In my program, I need to pull certian groupings of files and perform
> various operations on them...
>
> I first call :
>
> use File::Copy;
> use File::Find;
> use File::Path;
> use Time::localtime;
>
> my $sourcedir = "//server/incoming/dir/PROD/";
> my $workingdir = "c:/local/dir/";
>
> chdir $sourcedir;
> my $dateStamp = sprintf("%04d%02d%02d",
> (localtime->year+1900),(localtime->mon+1),localtime->mday);
> my @files = < *PendingTrades$dateStamp*.txt.pgp ) || warn("No Files
> actually found $!");
>
> foreach(@files)
> {
> print "Moving ==> $_\n";
> move($_,$workingdir) || handleError ("Move Failed : $!\n");
> }
>
> The above fails ... it returns only the first file out of any number
> of valid results.. even with NO results, @files still returns '1' .. no
> matter if I even specify "*"
>
> The following code set to work on the gatherd files is perfectly file
>
> chdir $workingdir;
> @files = < PendingTrades*.txt >;
> foreach(@files)
> {
>
> print "Working ==> $_\n";
> system("pgp +force -e \"".$_."\" \"xxxxxxx\""); # Encrypt File using
> public key
> move($_,$arch) || handleError ("Archive Failed : $!\n"); # move to
> archive dir
> &put($_.".pgp"); ## Send via FTP
> }
>
> all parts of this snippet work correctly, calling my various
> subroutines... and I get a valid list of files to operate on.. I need
> to chdir due to my windows paths having spaces..
>
> The first part above seems to only return a proper result set if I use
> :
>
> opendir(D, $sourcedir);
> my @files = grep {/PendingTrades$dateStamp/} readdir(D);
> closedir(D);
>
> Is this a quirk of activeperl on windows and remote UNC paths ??
| |
| ercdvs 2006-06-27, 6:57 pm |
| Is there a known bug / quirk in windows ports that makes building a 3rd
party module needed ?
I would like to keep it in core modules if possible, I just wasn't sure
if I had fallen into some common pitfall or made some stupid mistake.
saroo.maini@gmail.com wrote:
> hi,
>
> To retrieve certain files from the directory use the module use
> File::Find::Rule::Type. This module you can find in CPAN. and then use
> this command:
>
> my @files =
> File::Find::Rule->file()->name('*.txt')->in($directory_path);
>
> foreach my $fname(sort(@files))
> {
> print "file: $fname \n";
> }
>
>
|
|
|
|
|