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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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



FishMonger
Veteran / Moderator

Apr 27, 2009, 10:48 AM


Views: 8077
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.

Code
#!/usr/bin/perl 

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;
$totalfiles++;
my $sb = stat($file);
$sumsizefiles += $sb->size;
printf "%s %8.0f %s \n", $file, $sb->size, scalar localtime $sb->mtime;
}

closedir($DIRECT);

# 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.
http://search.cpan.org/~andya/File-Monitor-0.10/lib/File/Monitor.pm

Win32::FileSystem::Watcher - Watch a Win32 file system for changes (asynchronously).
http://search.cpan.org/~ank/Win32-FileSystem-Watcher-0.1.0/lib/Win32/FileSystem/Watcher.pm


(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