#!/usr/bin/perl ## $Id$ ## ## Author: David McKeon <@bonzoli.com> ## URL: http://bonzoli.com ## Program: del_empty_dirs ## Creation Date: Date: 2007/01/29 18:01:46 GMT ## Last Revision: $Date$ ## Revision: $Revision$ ## ############################################################################# # David McKeon <@bonzoli.com> http://bonzoli.com # # # # Copyright (C) 2007-2007 David McKeon. All rights reserved. # # # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the # # Free Software Foundation; either version 2 of the License, or (at your # # option) any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # # Public License for more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to: # # # # Free Software Foundation, Inc. # # 59 Temple Place - Suite 330 # # Boston, MA 02111-1307, USA. # # # # Or you can find the full GNU GPL online at: http://www.gnu.org # # # ############################################################################# ## Category: Perl ## Rating: 5/5 ## ## ## ## ## # #### These are missing? #### my $Date='Mon Jan 29 18:16:13 PST 2007'; # Creation Date my $date='Mon Jan 29 18:16:13 PST 2007'; # Last Revision Date my $Revision='.5'; my $Id=''; #### End Missing #### $| = 1; use Getopt::Long; use File::Find; #--------------------------------------------------------------------------- Getopt::Long::Configure("no_ignore_case"); GetOptions( "h|help" => \$help, "d|debug" => \$debug, "t|test" => \$test, "V|version" => \$vers, "p|path" =>\$path, #----------------------- ); #--------------------------------------------------------------------------- if($help){ exec("perldoc $0"); } if($vers){ version(); } if ($test) { finddepth(sub{print},'.'); exit } #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- sub version { my($date) = "\$Date$_"; my($rvsn) = "\$Revision$_"; my($rcsd) = "\$Id$_"; $date =~ s/(.*: +)(.*?)(\s*$)/$2/g; $rvsn =~ s/(.*: +)(.*?)(\s*$)/$2/g; $rcsd =~ s/(.*: +)(.*?)(\s*$)/$2/g; print < URL: http://bonzoli.com Creation Date: Mon Jan 29 18:16:13 PST 2007 Last Revision: Mon Jan 29 18:16:13 PST 2007 Revision: v.5 Copyright (C) 2007-2007 David McKeon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. Or you can find the full GNU GPL online at: http://www.gnu.org EOF exit; } #--------------------------------------------------------------------------- #Main# # This is sad, but we run rmdir against everything, it will only delete empty # directories, it does work though. finddepth(sub{rmdir},'.'); #end Main# #--------------------------------------------------------------------------- ## ## Use "perldoc del_empty_dirs" to read the man page below. # __END__ =head1 NAME B - description =head1 SYNOPSIS B S<[ B<-dhtv> ]> =head1 DESCRIPTION B deletes emptry directories below where it was run. Starting at the lowest directory in the tree first, and working upwards. We are basically running rmdir against everything from bottom to top, but rmdir will only delete empty directories, so this process does work. =head1 QUICK START The most common usage is as follows: B =head1 STANDARD OPTIONS B<-d --debug> Enables debugging code. Except in this script there is no debugging code, so this is just a placeholder. B<-h --help> Prints this information. B<-t --test> Prints we will run rmdir against without performing the operations, without performing the delete. B<-v --version> Prints version information. =head1 OPTIONS =head1 EXAMPLE The example below B [ B<-t> ] =head1 BUGS None. =head1 SEE ALSO del_empty_dirs =head1 AUTHOR AND COPYRIGHT David McKeon <@bonzoli.com> http://bonzoli.com Copyright (C) 2007-2007 David McKeon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. Or you can find the full GNU GPL online at: http://www.gnu.org =head1 VERSION Current Revision: $Revision$ Last Modification: $Date$ =pod SCRIPT CATEGORIES UNIX/System_administration =pod OSNAMES Any