#!/usr/bin/perl -w use strict; # # Each command-line argument is a file or directory # foreach my $file (@ARGV) { # # If it is a directory, read its contents # if (-d $file) { opendir(DIR, $file) or die "Can't read directory \"$file\": $!\n"; while (defined(my $sub_file = readdir(DIR))) { # # Check whether we find a sub-directory or a file in the # directory # if (-d "$file/$sub_file") { print "$sub_file is a directory\n"; } else { print "$sub_file is a file\n"; } } closedir(DIR); } # # It is not a directory, so print its size and age. I use printf # for nice formatting, but that is not required. # else { printf("%s contains %d bytes and was last modified %.1f days ago.\n", $file, -s $file, -M $file); } }