RE: Help with File::Find

2003-03-10 Thread Kipp, James
> > find {
> > preprocess => sub { grep( /My\s+Documents/, @_) },
> > wanted => sub { print "$File::Find::name\n"}
> > }, 'c:/test2';
> 
> Firstly don't forget that Windows treats the 'My Documents' directory
> as a special case. Windows Explorer shows it at the same tree level
> as My Computer and Recycle Bin, and it has no disk device associated
> with it. Fortunatley Fil::Find will find it in '/', whichever 
> disk drive
> happens to be the current one.

C:\test2 was just a mock directory to emulate the network folder i was
dealing with.  The actual server\directory has a folder foreach user and
each contains a 'data' directory with one or more DFS links and a physical
'My Documents' directory. SO it is not the actual 'My Documents' directory i
think that you were referring to above. 

> 
> Secondly, the preprocess routine is called with $File::Find::name set
> to the current directory being processed, while @_ holds the names
> of all files and directories contained here. The idea is that you must
> return the subset of @_ in which you are interested: File::Find will
> continue to process only those files which remain. (This means that
> excluded files will not be passed to the wanted routine, and
> excluded directories will be removed from the directory tree.
> 
> What you need to do then, is to include all of those files where
> 'My Documents' is in either $File::Find::name or @_. One way
> to do this is to write:
> 
> preprocess => sub {
> ($File::Find::name =~ m(/My Documents\b)
> ? @_
> : grep { $_ eq q(My Documents) } @_
> )
> },
> 
> However, having said all that, the best solution to this
> particular problem is:
> 
> find {
> wanted => sub { print "$File::Find::name\n"}
> }, '/My Documents';
> 
> unless you have a 'My Documents' directory beneath C:/test2?

See my explanation above. Thanks for your help. 

Jim




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



Re: Help with File::Find

2003-03-08 Thread Rob Dixon
James Kipp wrote:
> Steve's suggestions worked great for ignoring or not recursing
> directories, but I am unable to filter out all directories not named
> "My Documents" . I have tried using regex and grep to filter them out
> but no luck
>
> this fails, just goes to the root directory and exits, and the docs
> really don't say
> how the preprocess option works :
>
> find {
> preprocess => sub { grep( /My\s+Documents/, @_) },
> wanted => sub { print "$File::Find::name\n"}
> }, 'c:/test2';

Firstly don't forget that Windows treats the 'My Documents' directory
as a special case. Windows Explorer shows it at the same tree level
as My Computer and Recycle Bin, and it has no disk device associated
with it. Fortunatley Fil::Find will find it in '/', whichever disk drive
happens to be the current one.

Secondly, the preprocess routine is called with $File::Find::name set
to the current directory being processed, while @_ holds the names
of all files and directories contained here. The idea is that you must
return the subset of @_ in which you are interested: File::Find will
continue to process only those files which remain. (This means that
excluded files will not be passed to the wanted routine, and
excluded directories will be removed from the directory tree.

What you need to do then, is to include all of those files where
'My Documents' is in either $File::Find::name or @_. One way
to do this is to write:

preprocess => sub {
($File::Find::name =~ m(/My Documents\b)
? @_
: grep { $_ eq q(My Documents) } @_
)
},

However, having said all that, the best solution to this
particular problem is:

find {
wanted => sub { print "$File::Find::name\n"}
}, '/My Documents';

unless you have a 'My Documents' directory beneath C:/test2?

HTH,

Rob







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



Re: Help with File::Find

2003-03-07 Thread Steve Grazzini
James Kipp <[EMAIL PROTECTED]> writes:
> 
> Thanks Steve. 
> So I could use either one of these methods, like: 
> 
> # skip dirs with Profile 
> find {
>   preprocess => sub { grep !/Profile/, @_ },
>   wanted => sub { print if ($File::Find::name =~ /.*\.pst$/) }
> }, 'f:/users/user1';
> ---
> 
> or 
> # don't recurse tree that matches pattern:
> 
> find sub {
> if ($_ eq "DBM") { ++$File::Find::prune }
> print "$File::Find::name\n";
> }, 'f:/users/user1';
> 

Exactly.  (Those are much better than my examples ;)

-- 
Steve

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



RE: Help with File::Find

2003-03-07 Thread Kipp, James
Steve's suggestions worked great for ignoring or not recursing directories,
but I am unable to filter out all directories not named "My Documents" . I
have tried using regex and grep to filter them out but no luck
 
this fails, just goes to the root directory and exits, and the docs really
don't say
how the preprocess option works :
 
find { 
preprocess => sub { grep( /My\s+Documents/, @_) },
wanted => sub { print "$File::Find::name\n"}
}, 'c:/test2';

--- 
pruning also fails if i try to weed out all but "My Documents" 
find sub {
if ($_ !~ /My\s+Documents/) { ++$File::Find::prune }
print "$File::Find::name\n";
}, 'c:/test2';

I get the same result as above. Help...

Thanks
Jim



 


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



RE: Help with File::Find

2003-03-07 Thread Kipp, James
> Of course.
> 
>   #!/usr/bin/perl -l
> 
>   use File::Find;
>   use warnings;
> 
>   #
>   # ignore
>   #
>   find { 
> preprocess => sub { grep $_ ne __FILE__, @_ },
> wanted => sub { print }
>   }, ".";
> 
>   #
>   # don't recurse
>   #
>   find sub {
> if ($_ eq __FILE__) { ++$File::Find::prune }
> print;
>   }, ".";


Thanks Steve. 
So I could use either one of these methods, like: 

# skip dirs with Profile 
find {
preprocess => sub { grep !/Profile/, @_ },
wanted => sub { print if ($File::Find::name =~ /.*\.pst$/) }
}, 'f:/users/user1';
---

or 
# don't recurse tree that matches pattern:

find sub {
if ($_ eq "DBM") { ++$File::Find::prune }
print "$File::Find::name\n";
}, 'f:/users/user1';





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



Re: Help with File::Find

2003-03-07 Thread Steve Grazzini
James Kipp <[EMAIL PROTECTED]> writes:
> Is there a way to get File::Find to TOTALLY ignore a directory?? 

Of course.

  #!/usr/bin/perl -l

  use File::Find;
  use warnings;

  #
  # ignore
  #
  find { 
preprocess => sub { grep $_ ne __FILE__, @_ },
wanted => sub { print }
  }, ".";

  #
  # don't recurse
  #
  find sub {
if ($_ eq __FILE__) { ++$File::Find::prune }
print;
  }, ".";


HTH
-- 
Steve

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



Re: Help with File::Find

2002-01-11 Thread Nick_D_Montpetit


Michael,

Thanks for your help!  I'll bet that you have identified the problem, and
I'll do some testing to confirm it.  Unfortunately, the "ignore such
files..." option won't help very much, since the point of my code is to
identify those very files, so I guess I'll have to take the recompile
route.

 Thanks!

-Nick


   
 
Michael
 
Fowler   To: [EMAIL PROTECTED]   
 
         Subject: Re: Help with File::Find 
 
   
 
01/11/02   
 
01:17 PM   
 
   
 
   
 



On Fri, Jan 11, 2002 at 10:57:48AM -0600, [EMAIL PROTECTED]
wrote:
> all files (including the previously missed ones) are printed out (also
> along with the directories now) as expected, but for the files that would
> not have passed the (-e $_) test, the values assigned for filesize and
age
> in line 12 are (tested to be) undefined.  If this is any help, the files
> that don't pass the (-e $_) of test of line 11 are (perhaps
coincidentally)
> the biggest files (~55 GB)  in the directory.

I don't believe this is a coincidence.  Try stat'ing those largefiles
independently:

perl -wle 'print join("\n", stat($_)) foreach @ARGV' file1 file2 etc.

If you see undefined value warnings, as I suspect, then your Perl isn't
compiled to support large file sizes, and it's causing any stats on such
files to return undefined values.

In this case you have two solutions; ignore these files by not checking for
further information if stat returns an empty list, or recompile your Perl
with large file support (assuming your C libraries have such support).


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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






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




Re: Help with File::Find

2002-01-11 Thread Michael Fowler

On Fri, Jan 11, 2002 at 10:57:48AM -0600, [EMAIL PROTECTED] wrote:
> all files (including the previously missed ones) are printed out (also
> along with the directories now) as expected, but for the files that would
> not have passed the (-e $_) test, the values assigned for filesize and age
> in line 12 are (tested to be) undefined.  If this is any help, the files
> that don't pass the (-e $_) of test of line 11 are (perhaps coincidentally)
> the biggest files (~55 GB)  in the directory.

I don't believe this is a coincidence.  Try stat'ing those largefiles
independently:

perl -wle 'print join("\n", stat($_)) foreach @ARGV' file1 file2 etc.

If you see undefined value warnings, as I suspect, then your Perl isn't
compiled to support large file sizes, and it's causing any stats on such
files to return undefined values.

In this case you have two solutions; ignore these files by not checking for
further information if stat returns an empty list, or recompile your Perl
with large file support (assuming your C libraries have such support).

 
Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




Re: Help with File::Find

2002-01-11 Thread Nick_D_Montpetit


Thanks! In this case, at least, there aren't any symbolic links to worry
about.


   
  
"Tanton Gibbs" 
  

  
farms.com>cc:  
  
      Subject: Re: Help with File::Find
  
01/11/02 11:32 
  
AM 
  
   
  
   
  



-e might actually fail if they are symbolic links that don't exist...you
might check to make sure.
- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, January 11, 2002 12:27 PM
Subject: RE: Help with File::Find


>
> Bob Showalter
> ,
> white.com>   [EMAIL PROTECTED]
>  cc:
>         01/11/02 11:06 AMSubject: RE: Help
with File::Find
>
>
>
>
>
>
>
>
>
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, January 11, 2002 11:58 AM
> > To: [EMAIL PROTECTED]
> > Subject: Help with File::Find
> >
> >
> > Hi Everyone!
> >
> > I'm fairly new to Perl, and completely new to submitting to
> > the list, so
> > please be easy on me.  :-)
> >
> > The purpose of the code I wrote (listed below) is to go
> > through the current
> > directory and all of its subdirectories and report the
> > filename, size and
> > age of the x largest files, where x depends on the argument
> > supplied on the
> > command line and the number of files in the directory.  I'm
> > sure there's an
> > easier way to do this with a UNIX utility (or with Perl), but
> > this program
> > has been a good learning experience for me.
> >
> > The code below runs without any syntax errors, but File::Find
> > (which I love
> > and use frequently) or the -e file test doesn't give the
> > results I expect.
> > Specifically, my (explicit) checks show that the test in line
> > 11 does not
> > always evaluate to TRUE for values of $_ corresponding to
> > legitimate (i.e.,
> > existing and size > 0) files, which means I'm missing files
> > that should be
> > in my final output.  If I change line 11for debugging
> > purposes to simply
> >
> > if ($_){
> >
> > all files (including the previously missed ones) are printed out (also
> > along with the directories now) as expected, but for the
> > files that would
> > not have passed the (-e $_) test, the values assigned for
> > filesize and age
> > in line 12 are (tested to be) undefined.  If this is any
> > help, the files
> > that don't pass the (-e $_) of test of line 11 are (perhaps
> > coincidentally)
> > the biggest files (~55 GB)  in the directory.
>
> I don't really have an answer, but conceptually, why would you need
> a -e test at all? If the file doesn't exist, how would wanted() get
> called for it?
>
> Also, have you tried doing the -e on $File::Find::name instead of $_ ?
> Perhaps there's some problem in changing directories.
>
> Hi Bob,
>
> Thanks for the response! Good question:  My original code - which
produced
> the same results - used the -f test because I don't want to include
> directories in my final output.  I don't think the problem is with
changing
> directories, because within a given directory, some files will be listed
> and others will be omitted.
>
> Thanks!
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>






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




Re: Help with File::Find

2002-01-11 Thread John W. Krahn

Nick D Montpetit wrote:
> 
> Hi Everyone!

Hello,

> I'm fairly new to Perl, and completely new to submitting to the list, so
> please be easy on me.  :-)

I'll try.

> The purpose of the code I wrote (listed below) is to go through the current
> directory and all of its subdirectories and report the filename, size and
> age of the x largest files, where x depends on the argument supplied on the
> command line and the number of files in the directory.  I'm sure there's an
> easier way to do this with a UNIX utility (or with Perl), but this program
> has been a good learning experience for me.
> 
> The code below runs without any syntax errors, but File::Find (which I love
> and use frequently) or the -e file test doesn't give the results I expect.
> Specifically, my (explicit) checks show that the test in line 11 does not
> always evaluate to TRUE for values of $_ corresponding to legitimate (i.e.,
> existing and size > 0) files, which means I'm missing files that should be
> in my final output.  If I change line 11for debugging purposes to simply
> 
> if ($_){
> 
> all files (including the previously missed ones) are printed out (also
> along with the directories now) as expected, but for the files that would
> not have passed the (-e $_) test, the values assigned for filesize and age
> in line 12 are (tested to be) undefined.  If this is any help, the files
> that don't pass the (-e $_) of test of line 11 are (perhaps coincidentally)
> the biggest files (~55 GB)  in the directory.
> 
> I've researched the File::Find documentation and checked the FAQ's with no
> luck, so I'm hoping someone out there can help me.
> 
> Also, is there a function that returns a minimum value in an array?  It's
> not my biggest concern right now, but it would make line 20 simpler.
> 
>  1: #!/usr/local/bin/perl -w
>  2:
>  3: use Cwd;
>  4: use File::Find;
>  5: use FileHandle;
>  6:
>  7: ($filecount = shift) || ($filecount = 20);
>  8:
>  9: sub wanted{
> 10:  my $flag = 0;
> 11:  if (-e $_){
> 12:   push(@filelist, [$File::Find::name, -s $_, -M $_]);
> 13:}
> 14:  }
> 15:
> 16: $dir = cwd();
> 17:
> 18: find(\&wanted,$dir);
> 19:
> 20: foreach $fileref ((sort {$b->[1] <=> $a->[1]} @filelist)[0..(sort( {$a
> <=>$b} $filecount,scalar(@filelist)-1))[0]]){
> 21:  write STDOUT;
> 22:  }
> 23:
> 24: STDOUT -> format_name("STDOUT_BOT");
> 25: write STDOUT;
> 26:
> 27: format STDOUT_TOP=
> 28: FILENAME
> FILE SIZE (BYTES)  AGE (DAYS)
> 29:
> 
>--
> 30: .
> 31: format STDOUT=
> 32:
> @<<<
> 
> @>>>
> 33: $fileref->[0], $fileref->[1], sprintf("%4.0f", ($fileref->[2]))
> 34: .
> 35: format STDOUT_BOT=
> 36:
> 
>-
> 37: .
> .


Here is something that I think does what you want:

#!/usr/local/bin/perl -w
use strict;
use Cwd;
use File::Find;
use FileHandle;

my $filecount = shift || 20;
my @filelist;
our $fileref;

# This stores _at most_ $filecount entries in @filelist so sorting is
fast
# and you don't have to store _all_ file names.  Also int(-M $_) since
you
# are only reporting the age in days.  Files are stored with the largest
# file at the top of the array @filelist (largest, second largest, third
# largest, ... $filecount largest)
sub wanted {
@filelist = sort { $b->[1] <=> $a->[1] } ( @filelist, [
$File::Find::name, -s $_, int(-M $_) ] );
pop @filelist if @filelist > $filecount;
}

my $dir = cwd();

find( \&wanted, $dir );

for $fileref ( @filelist ) {
write STDOUT;
}

STDOUT->format_name("STDOUT_BOT");
write STDOUT;

# the rest of the program is unchanged from original



John
-- 
use Perl;
program
fulfillment

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




Re: Help with File::Find

2002-01-11 Thread Nick_D_Montpetit


I meant to post my original code, where line 11 used the -f file test (so
that directories wouldn't be included in the output).  My questions still
apply when using -f instead of -e. If we could refer the email below for
future discussion, that would be great!  Sorry about the screwup.  :-)

Thanks!

-Nick


   
 
Nick_D_Montpetit@  
 
eFunds.com   To: [EMAIL PROTECTED]
 
 cc:   
 
01/11/02 10:57 AMSubject: Help with File::Find 
 
   
 
   
 



Hi Everyone!

I'm fairly new to Perl, and completely new to submitting to the list, so
please be easy on me.  :-)

The purpose of the code I wrote (listed below) is to go through the current
directory and all of its subdirectories and report the filename, size and
age of the x largest files, where x depends on the argument supplied on the
command line and the number of files in the directory.  I'm sure there's an
easier way to do this with a UNIX utility (or with Perl), but this program
has been a good learning experience for me.

The code below runs without any syntax errors, but File::Find (which I love
and use frequently) or the -f file test doesn't give the results I expect.
Specifically, my (explicit) checks show that the test in line 11 does not
always evaluate to TRUE for values of $_ corresponding to legitimate (i.e.,
existing and size > 0) files, which means I'm missing files that should be
in my final output.  If I change line 11for debugging purposes to simply

if ($_){

all files (including the previously missed ones) are printed out (also
along with the directories now) as expected, but for the files that would
not have passed the (-f $_) test, the values assigned for filesize and age
in line 12 are (tested to be) undefined.  If this is any help, the files
that don't pass the (-f $_) of test of line 11 are (perhaps coincidentally)
the biggest files (~55 GB)  in the directory.

I've researched the File::Find documentation and checked the FAQ's with no
luck, so I'm hoping someone out there can help me.

Also, is there a function that returns a minimum value in an array?  It's
not my biggest concern right now, but it would make line 20 simpler.

 1: #!/usr/local/bin/perl -w
 2:
 3: use Cwd;
 4: use File::Find;
 5: use FileHandle;
 6:
 7: ($filecount = shift) || ($filecount = 20);
 8:
 9: sub wanted{
10:  my $flag = 0;
11:  if (-f $_){
12:   push(@filelist, [$File::Find::name, -s $_, -M $_]);
13:}
14:  }
15:
16: $dir = cwd();
17:
18: find(\&wanted,$dir);
19:
20: foreach $fileref ((sort {$b->[1] <=> $a->[1]} @filelist)[0..(sort( {$a
<=>$b} $filecount,scalar(@filelist)-1))[0]]){
21:  write STDOUT;
22:  }
23:
24: STDOUT -> format_name("STDOUT_BOT");
25: write STDOUT;
26:
27: format STDOUT_TOP=
28: FILENAME
FILE SIZE (BYTES)  AGE (DAYS)
29:
--

30: .
31: format STDOUT=
32:
@<<< 


@>>>
33: $fileref->[0], $fileref->[1], sprintf("%4.0f", ($fileref->[2]))
34: .
35: format STDOUT_BOT=
36:
-

37: .
...


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






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




RE: Help with File::Find

2002-01-11 Thread Nick_D_Montpetit

   
 
Bob Showalter  
 
, 
white.com>   [EMAIL PROTECTED]
 
 cc:   
 
01/11/02 11:06 AMSubject:     RE: Help with File::Find 
 
   
 
   
 







> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 11, 2002 11:58 AM
> To: [EMAIL PROTECTED]
> Subject: Help with File::Find
>
>
> Hi Everyone!
>
> I'm fairly new to Perl, and completely new to submitting to
> the list, so
> please be easy on me.  :-)
>
> The purpose of the code I wrote (listed below) is to go
> through the current
> directory and all of its subdirectories and report the
> filename, size and
> age of the x largest files, where x depends on the argument
> supplied on the
> command line and the number of files in the directory.  I'm
> sure there's an
> easier way to do this with a UNIX utility (or with Perl), but
> this program
> has been a good learning experience for me.
>
> The code below runs without any syntax errors, but File::Find
> (which I love
> and use frequently) or the -e file test doesn't give the
> results I expect.
> Specifically, my (explicit) checks show that the test in line
> 11 does not
> always evaluate to TRUE for values of $_ corresponding to
> legitimate (i.e.,
> existing and size > 0) files, which means I'm missing files
> that should be
> in my final output.  If I change line 11for debugging
> purposes to simply
>
> if ($_){
>
> all files (including the previously missed ones) are printed out (also
> along with the directories now) as expected, but for the
> files that would
> not have passed the (-e $_) test, the values assigned for
> filesize and age
> in line 12 are (tested to be) undefined.  If this is any
> help, the files
> that don't pass the (-e $_) of test of line 11 are (perhaps
> coincidentally)
> the biggest files (~55 GB)  in the directory.

I don't really have an answer, but conceptually, why would you need
a -e test at all? If the file doesn't exist, how would wanted() get
called for it?

Also, have you tried doing the -e on $File::Find::name instead of $_ ?
Perhaps there's some problem in changing directories.

Hi Bob,

Thanks for the response! Good question:  My original code - which produced
the same results - used the -f test because I don't want to include
directories in my final output.  I don't think the problem is with changing
directories, because within a given directory, some files will be listed
and others will be omitted.

Thanks!




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




RE: Help with File::Find

2002-01-11 Thread John Edwards

Something I just found via a google search...

foreach (@_) {
$min = $_ if $min > $_;
}

$min now holds the smallest value of the array.

BTW, shouldn't line 21 be write $fileref STDOUT? I've not gone over the
code, but if you are looking for the smallest array value, then only writing
out once that's been found I'd guess you were trying to write out that
value.

John

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: 11 January 2002 16:58
To: [EMAIL PROTECTED]
Subject: Help with File::Find


Hi Everyone!

I'm fairly new to Perl, and completely new to submitting to the list, so
please be easy on me.  :-)

The purpose of the code I wrote (listed below) is to go through the current
directory and all of its subdirectories and report the filename, size and
age of the x largest files, where x depends on the argument supplied on the
command line and the number of files in the directory.  I'm sure there's an
easier way to do this with a UNIX utility (or with Perl), but this program
has been a good learning experience for me.

The code below runs without any syntax errors, but File::Find (which I love
and use frequently) or the -e file test doesn't give the results I expect.
Specifically, my (explicit) checks show that the test in line 11 does not
always evaluate to TRUE for values of $_ corresponding to legitimate (i.e.,
existing and size > 0) files, which means I'm missing files that should be
in my final output.  If I change line 11for debugging purposes to simply

if ($_){

all files (including the previously missed ones) are printed out (also
along with the directories now) as expected, but for the files that would
not have passed the (-e $_) test, the values assigned for filesize and age
in line 12 are (tested to be) undefined.  If this is any help, the files
that don't pass the (-e $_) of test of line 11 are (perhaps coincidentally)
the biggest files (~55 GB)  in the directory.

I've researched the File::Find documentation and checked the FAQ's with no
luck, so I'm hoping someone out there can help me.

Also, is there a function that returns a minimum value in an array?  It's
not my biggest concern right now, but it would make line 20 simpler.

 1: #!/usr/local/bin/perl -w
 2:
 3: use Cwd;
 4: use File::Find;
 5: use FileHandle;
 6:
 7: ($filecount = shift) || ($filecount = 20);
 8:
 9: sub wanted{
10:  my $flag = 0;
11:  if (-e $_){
12:   push(@filelist, [$File::Find::name, -s $_, -M $_]);
13:}
14:  }
15:
16: $dir = cwd();
17:
18: find(\&wanted,$dir);
19:
20: foreach $fileref ((sort {$b->[1] <=> $a->[1]} @filelist)[0..(sort( {$a
<=>$b} $filecount,scalar(@filelist)-1))[0]]){
21:  write STDOUT;
22:  }
23:
24: STDOUT -> format_name("STDOUT_BOT");
25: write STDOUT;
26:
27: format STDOUT_TOP=
28: FILENAME
FILE SIZE (BYTES)  AGE (DAYS)
29:

--
30: .
31: format STDOUT=
32:
@<<<
 

@>>>
33: $fileref->[0], $fileref->[1], sprintf("%4.0f", ($fileref->[2]))
34: .
35: format STDOUT_BOT=
36:

-
37: .
...


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


--Confidentiality--.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



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




RE: Help with File::Find

2002-01-11 Thread Kipp, James


>  8:
>  9: sub wanted{
> 10:  my $flag = 0;
> 11:  if (-e $_){
> 12:   push(@filelist, [$File::Find::name, -s $_, -M $_]);

don't know if you need the -e here, it is redundant. you might want to use
-f test to just find and stat regular files. here is a snip from a script i
did and use alot and works great:
--
sub wanted
{
# if there are dirs you want to skip
next if ($File::Find::dir =~ /^(MediaCreate)+/);
next if ($File::Find::dir =~ /^(Lan)+/);
#***only want files***
return unless (-f $_);

if((($age = -M $_) > 60) && (($size = -s $_) > 1024 ** 2 * 50)) {
print LOG
"$File::Find::name\t".int($age)."\t".BytesToMeg($size)."\tMB\n"; 
}
---


> 20: foreach $fileref ((sort {$b->[1] <=> $a->[1]} 
> @filelist)[0..(sort( {$a
> <=>$b} $filecount,scalar(@filelist)-1))[0]]){

hmm.. this line is confusing, not sure if you need all of that
and do you really need to use format below? 
i would think some printf would be fine


> 21:  write STDOUT;
> 22:  }
> 23:
> 24: STDOUT -> format_name("STDOUT_BOT");
> 25: write STDOUT;
> 26:
> 27: format STDOUT_TOP=
> 28: FILENAME
> FILE SIZE (BYTES)  AGE (DAYS)
> 29:
> --
> 
> 30: .
> 31: format STDOUT=
> 32:
> @<
> << 
> 
> @>>>
> 33: $fileref->[0], $fileref->[1], sprintf("%4.0f", ($fileref->[2]))
> 34: .
> 35: format STDOUT_BOT=
> 36:
> --
> ---
> 37: .
> ..
> 
> 


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




RE: Help with File::Find

2002-01-11 Thread Bob Showalter

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 11, 2002 11:58 AM
> To: [EMAIL PROTECTED]
> Subject: Help with File::Find
> 
> 
> Hi Everyone!
> 
> I'm fairly new to Perl, and completely new to submitting to 
> the list, so
> please be easy on me.  :-)
> 
> The purpose of the code I wrote (listed below) is to go 
> through the current
> directory and all of its subdirectories and report the 
> filename, size and
> age of the x largest files, where x depends on the argument 
> supplied on the
> command line and the number of files in the directory.  I'm 
> sure there's an
> easier way to do this with a UNIX utility (or with Perl), but 
> this program
> has been a good learning experience for me.
> 
> The code below runs without any syntax errors, but File::Find 
> (which I love
> and use frequently) or the -e file test doesn't give the 
> results I expect.
> Specifically, my (explicit) checks show that the test in line 
> 11 does not
> always evaluate to TRUE for values of $_ corresponding to 
> legitimate (i.e.,
> existing and size > 0) files, which means I'm missing files 
> that should be
> in my final output.  If I change line 11for debugging 
> purposes to simply
> 
> if ($_){
> 
> all files (including the previously missed ones) are printed out (also
> along with the directories now) as expected, but for the 
> files that would
> not have passed the (-e $_) test, the values assigned for 
> filesize and age
> in line 12 are (tested to be) undefined.  If this is any 
> help, the files
> that don't pass the (-e $_) of test of line 11 are (perhaps 
> coincidentally)
> the biggest files (~55 GB)  in the directory.

I don't really have an answer, but conceptually, why would you need
a -e test at all? If the file doesn't exist, how would wanted() get
called for it?

Also, have you tried doing the -e on $File::Find::name instead of $_ ?
Perhaps there's some problem in changing directories.

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




RE: Help with File::Find

2002-01-11 Thread Wagner-David

$_ in the Find::File setup has only the filename.  You need to check 
$Find::File::name which holds the full filename.

Wags ;)

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 11, 2002 08:58
To: [EMAIL PROTECTED]
Subject: Help with File::Find


Hi Everyone!

I'm fairly new to Perl, and completely new to submitting to the list, so
please be easy on me.  :-)

The purpose of the code I wrote (listed below) is to go through the current
directory and all of its subdirectories and report the filename, size and
age of the x largest files, where x depends on the argument supplied on the
command line and the number of files in the directory.  I'm sure there's an
easier way to do this with a UNIX utility (or with Perl), but this program
has been a good learning experience for me.

The code below runs without any syntax errors, but File::Find (which I love
and use frequently) or the -e file test doesn't give the results I expect.
Specifically, my (explicit) checks show that the test in line 11 does not
always evaluate to TRUE for values of $_ corresponding to legitimate (i.e.,
existing and size > 0) files, which means I'm missing files that should be
in my final output.  If I change line 11for debugging purposes to simply

if ($_){

all files (including the previously missed ones) are printed out (also
along with the directories now) as expected, but for the files that would
not have passed the (-e $_) test, the values assigned for filesize and age
in line 12 are (tested to be) undefined.  If this is any help, the files
that don't pass the (-e $_) of test of line 11 are (perhaps coincidentally)
the biggest files (~55 GB)  in the directory.

I've researched the File::Find documentation and checked the FAQ's with no
luck, so I'm hoping someone out there can help me.

Also, is there a function that returns a minimum value in an array?  It's
not my biggest concern right now, but it would make line 20 simpler.

 1: #!/usr/local/bin/perl -w
 2:
 3: use Cwd;
 4: use File::Find;
 5: use FileHandle;
 6:
 7: ($filecount = shift) || ($filecount = 20);
 8:
 9: sub wanted{
10:  my $flag = 0;
11:  if (-e $_){
12:   push(@filelist, [$File::Find::name, -s $_, -M $_]);
13:}
14:  }
15:
16: $dir = cwd();
17:
18: find(\&wanted,$dir);
19:
20: foreach $fileref ((sort {$b->[1] <=> $a->[1]} @filelist)[0..(sort( {$a
<=>$b} $filecount,scalar(@filelist)-1))[0]]){
21:  write STDOUT;
22:  }
23:
24: STDOUT -> format_name("STDOUT_BOT");
25: write STDOUT;
26:
27: format STDOUT_TOP=
28: FILENAME
FILE SIZE (BYTES)  AGE (DAYS)
29:
--
30: .
31: format STDOUT=
32:
@<<< 

@>>>
33: $fileref->[0], $fileref->[1], sprintf("%4.0f", ($fileref->[2]))
34: .
35: format STDOUT_BOT=
36:
-
37: .
...


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

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