[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] recursive delete



>From owner-macperl-anyperl@cfcl.com  Sun Jun 27 01:13:38 1999 sorry for
>the delay]
Message-Id: <v04205102b39b8a65bdbb@[199.165.65.84]>
In-Reply-To: <199906261100.EAA05753@cfcl.com>
References: <199906261100.EAA05753@cfcl.com>
Date: Sun, 27 Jun 1999 00:05:06 -0800

Hello,

Is there a good way to recursively delete a directory and all of its
subdirectories?  I've attempted to do this with the following code,
but it doesn't work.  (I'm programming this on my Mac, but it's
intended to work on a Apache UNIX machine...)

##########
# Recursively delete directory
#	routine is called by passing in a directory to be deleted, in $_[0]
#
sub delete_directory {
	opendir(DIRECTORY, "$_[0]") or die;
	@directories = grep !/\./, readdir DIRECTORY;
	unless (@directories eq "") {
		foreach $directory (@directories) { delete_directory
($_[0]/$directory); }
	}
	@files = readdir DIRECTORY;
	unlink @files;
	rmdir $_[0] or die;
}
#
##########

Thanks for any help!
				-Jeremy
---------------------------------------------------------
-	jeremy@alaskanweb.net				-
-	(PGP available on request)			-
-	http://AlaskanWeb.net/ -  Fast and Inexpensive! -
-	Web hosting, Web design & Computer Consulting	-
---------------------------------------------------------

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org