readdir() will give you the file name (leaf name). For the file size you can use the
stat() function.
What do you mean by "file type" - it could mean many things? Do you just need the suffix of the file name, or do you actually want to parse the contents of the file to see if its structure conforms to a list of known file structures. For the latter, have a look at File::MMagic.
One common trip-up for people using readdir() is that they forget that they need to prepend the parent directory path to obtain a complete path. This is especially true when passing the file name to another function. Here is a good idiom to follow:
opendir(D, $dir) or die "unable to read $dir: $!"
while (defined(my $leaf = readdir(D))) {
my $path = "$dir/$leaf"; # perhaps use File::Spec here
...
some_function($path); # often passing $leaf here is a mistake
...
}
closedir(D);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.