in reply to Re: Re: Re: (golf) Recursively delete empty directories from a tree
in thread (golf) Recursively delete empty directories from a tree

finddepth sub {(!-d or /^.{1,2}$/);rmdir},@ARGV;

That makes the test a seperate statement from the action (rmdir). So the test is doing nothing and you are running rmdir on everything, which fails silently for files and non empty directories. Change rmdir to print to see it, thats how I tested my version.

No idea why my version won't work for you it runs OK for me :)

--
Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

  • Comment on Re: Re: Re: Re: (golf) Recursively delete empty directories from a tree

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: (golf) Recursively delete empty directories from a tree
by zentara (Cardinal) on Feb 20, 2004 at 16:53 UTC
    Well I'm using Perl5.80. I setup a test directory like so:
    /1
    /2
    /3
    /4
    /5--
        \__
           \1
           \2
           \3
             \howdy
    
    Everythings empty except for the empty file 'howdy'. If I run your code from the top with "deldir .":
    use File::Find; finddepth sub {(!-d or /^.{1,2}$/)||rmdir($_); warn $File::Find::name,$! if $! =~ /not empty/},@ARGV;
    I get no output at all and the script dosn't remove anything.

    If I run the following:

    use File::Find; finddepth sub {(!-d or /^.{1,2}$/);rmdir($_); warn $File::Find::name,$! if $! =~ /not empty/},@ARGV;
    Everything gets deleted giving this output:
    ./5/3Directory not empty at ./delete-empty-dirs-recursive1 line 10.
    ./5Directory not empty at ./delete-empty-dirs-recursive1 line 10.
    
    I see what you are saying about the -d test not being performed, but I don't see how your code runs. Maybe you have a magic machine. If you or someone can explain why your code dosn't run on my machine, I would be grateful.

    I'm not really a human, but I play one on earth. flash japh