in reply to How to delete empty files

On posix (unix, linux, etc)
find ./path -type f -empty -exec rm '{}' \;
Or use File::Find::Rule
#!/usr/bin/perl use strict; use warnings; use Smart::Comments '###'; use File::Find::Rule; my $f = new File::Find::Rule->file()->empty(); my @files = $f->in($ENV{HOME}); # where to look ### @files for my $abs_file( @files ) { unlink $abs_file or die("cant unlink $abs_file, $!"); } # or use map # map { unlink $_ } @files;

Replies are listed 'Best First'.
Re^2: How to delete empty files
by padawan_linuxero (Scribe) on Jan 11, 2008 at 00:37 UTC
    HI
    your example gave me an error message
    Use of uninitialized value in string eq at C:/Perl/site/lib/File/Find/ +Rule.pm line 586. Use of uninitialized value in substitution (s///) at C:/Perl/site/lib/ +File/Find/Rule.pm line 586. Use of uninitialized value in substitution (s///) at C:/Perl/site/lib/ +File/Find/Rule.pm line 586. invalid top directory at C:/Perl/lib/File/Find.pm line 593.

      It seems that what gave you an error message was "C:/Perl/lib/File/Find.pm line 593", to be more precise 'invalid top directory'.

      What is your directory argument? Are you leaving it at $ENV{HOME} ? Is this environment variable even set on a windows system?

      Add this to the first lines of code, before we instance File::Find::Rule..

      defined $ENV{HOME} or die("ENV HOME is not defined."); print STDERR " # env home is set at $ENV{HOME}\n"; -d $ENV{HOME} or die("ENV HOME is not a directory");
      (You can always bite the bullet and switch to linux. It takes about a year to get comfortable, if you're considering.)

      Furthermore, *DONT RUN THAT SCRIPT*, it's just an example script! :-)

      Substitute $ENV{HOME} with something like 'C:\path\to\where\you\suspect\empty\files\reside'.

      And *read* File::Find::Rule!

      Don't give up so easily- if something does not work, that's when you start 'debugging'. Takes up most of my time, between tests (.t) and errors, and the fact that a third of my code is to check and recheck return values and results.. In the long run it's saved me a lot of sweat and blood.