|
|
| andrewmchorney@cox.net 2005-11-21, 6:57 pm |
| Hello
I got the file command to work but it is not as complete as I would have hoped for. I was hoping to get the file size and directory of the file so I could put them into arrays. Is there a way I can do it with the find command?
Andrew
| |
| usenet@DavidFilmer.com 2005-11-21, 6:57 pm |
| andrewmchorney@cox.net wrote:
> I was hoping to get the file size and directory of the file so I could put them
> into arrays. Is there a way I can do it with the find command?
Hey, another chance to highlight the wonders of my favorite module,
IO::All. I'll show how to print the values, but putting them into an
array is an exercise left to the OP (who didn't define the desired
array structure). The OP didn't mention how deep s/he wants to recurse;
this example demonstrates full recursion:
#!/usr/bin/perl
use strict; use warnings;
use IO::All;
printf "%s\n\tPATH:\t%s\n\tSIZE:\t%s\n", $_, $_->filepath, $_->size
for io("/path/to/my/directory") -> all_files(0);
__END__
See how easy life is with IO::All?
| |
| Purl Gurl 2005-11-21, 6:57 pm |
| andrewmchorney wrote:
> I was hoping to get the file size and directory of the file so I could put them into arrays.
This will point you in the right direction. A few minor modifications are only needed for your task.
http://www.purlgurl.net/~purlgurl/p...t/dir_list.html
Purl Gurl
| |
| xicheng 2005-11-21, 6:57 pm |
| andrewmchorney@cox.net wrote:
-------
> Hello
> I got the file command to work but it is not as complete as I would have hoped for. I was hoping to get the file size and directory of the file so I could put them into arrays. Is there a way I can do it with the find command?
-----
If you meant the Linux command "find", maybe you can try:
my @array = `find -type f -ls | perl -alne 'print
"$F[6]\t$F[10]"'`;
make sure if file-size and file-name is the 7th and 11th columns in you
output of the command:
find -type f -ls
Hope this helps,
XC
| |
| Chris Charley 2005-11-21, 9:56 pm |
| > Hello
>
> I got the file command to work but it is not as complete as I would have
> hoped for. I was hoping to get the file size and directory of the file so
> I could put them into arrays. Is there a way I can do it with the find
> command?
>
> Andrew
>
Yes, File::Find will provide the directory.
For file size, see http://perldoc.perl.org/functions/-X.html
| |
| Timothy Johnson 2005-11-21, 9:56 pm |
|
Don't forget that each module has documentation that can be accessed via
'perldoc Module::Name'
So try 'perldoc File::Find' (without the quotes) at the command-prompt.
Hint: Check the section called "The Wanted Function".
For the file size, you will probably use the stat function. One way to
do this is to use an array slice like so:
my $dirsize =3D (stat $_)[7];
Hint: File::Find sets $_ to the current filename. Do a 'perldoc -f
stat' to see what the other elements are that might be useful. 7 is the
file size in bytes.
Remember that the "Wanted" function (BadNames in your case) will execute
for each file.
-----Original Message-----
From: andrewmchorney@cox.net [mailto:andrewmchorney@cox.net]=20
Sent: Monday, November 21, 2005 1:38 PM
To: beginners@perl.org
Subject: File Finding=20
Hello
I got the file command to work but it is not as complete as I would have
hoped for. I was hoping to get the file size and directory of the file
so I could put them into arrays. Is there a way I can do it with the
find command?
Andrew
|
|
|
|