CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Win32 Programming Help: Re: [gixxer05] No results from using GetFileTime and getFileSize: Edit Log

Veteran / Moderator

Apr 27, 2009, 10:48 AM

Views: 19240
Re: [gixxer05] No results from using GetFileTime and getFileSize

You should always use the full path when doing the stat and you should declare your vars in the smallest scope that they need.

In almost all cases, it's better to use forward slashes in paths rather than backslashes.

Please use proper indentation. Your complete lack of indentation makes your code difficult to read/follow.

Try this cleaned up version.


use warnings;
use strict;
use File::stat;

while(1) {

my $subdirs;
my $totalfiles;
my $sumsizefiles;
my $dname = "C:/Reports";

opendir(my $DIRECT, $dname) or die "Can't open directory $dname: $!";

while ( my $file = readdir($DIRECT) ) {
$file = "$dname/$file";
$subdirs++ and next if -d $file;
my $sb = stat($file);
$sumsizefiles += $sb->size;
printf "%s %8.0f %s \n", $file, $sb->size, scalar localtime $sb->mtime;


# Print the total files and sum of file sizes
printf "\n%3d File(s) %d KB\n", $totalfiles, $sumsizefiles/1024;
print "Not including $subdirs Sub Directories\n";

sleep 5;

You may want to take a look at these modules.

File::Monitor - Monitor files and directories for changes.

Win32::FileSystem::Watcher - Watch a Win32 file system for changes (asynchronously).

(This post was edited by FishMonger on Apr 27, 2009, 10:49 AM)

Edit Log:
Post edited by FishMonger (Veteran) on Apr 27, 2009, 10:49 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives