Ormus has asked for the wisdom of the Perl Monks concerning the following question:
New to Perl, and using 5.8.8
I am trying to scan all the files in a folder and determine which ones have a file size greater then zero. Eventually will delete all files in that folder using unlink that have a file size greater then zero. I wrote this script that seems to be "should" work, but when I print, it prints the files that have a file size of zero as well (prints all the files).
$testfolder = '.\test'; $testfolder =~ s/\//\\/g; opendir Sdir, $testfolder; @files = readdir(Sdir); undef @newfiles; foreach $file (@files) { $full_pathname = $testfolder . "/" . $file; my ($filesize) = (stat $full_pathname)[7]; if ($filesize > 0) { $full_pathname = $testfolder . "/" . $file; if (-e $full_pathname) { @newfiles = (@newfiles,$file1); } } } foreach $file1 (@files) { print "$file1\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Stat and file size
by shmem (Chancellor) on Jul 28, 2012 at 19:43 UTC | |
Re: Stat and file size
by Kenosis (Priest) on Jul 28, 2012 at 19:46 UTC | |
by jwkrahn (Abbot) on Jul 29, 2012 at 06:45 UTC | |
by Ormus (Initiate) on Jul 28, 2012 at 20:01 UTC | |
by Kenosis (Priest) on Jul 28, 2012 at 20:09 UTC | |
Re: Stat and file size
by tobyink (Canon) on Jul 28, 2012 at 20:24 UTC | |
Re: Stat and file size
by Ormus (Initiate) on Jul 28, 2012 at 19:59 UTC | |
by Ormus (Initiate) on Jul 28, 2012 at 20:07 UTC | |
by tokpela (Chaplain) on Jul 29, 2012 at 16:12 UTC | |
by Kenosis (Priest) on Jul 28, 2012 at 20:12 UTC | |
by Anonymous Monk on Jul 28, 2012 at 20:22 UTC | |
by Ormus (Initiate) on Jul 28, 2012 at 20:26 UTC |
Back to
Seekers of Perl Wisdom