Morning, afternoon, evening,

Could I please have an example of the rmtree function.  Everytime I try to
run this function my script dies on me.  I'm sure I'm just missing a small
part of it.

Any help would be appreciated.  Thank you and have a great day.

Chris

 chdir "/u311/world/b25/MAN3/spc" or die $!;
 # chdir "/u11/tmp" or die $!;

 opendir(HERE, '.');

 @AllFiles = readdir(HERE);

 foreach $Name (@AllFiles) {

   if (-f $Name) {next}

   if ((-d $Name) and ($Name =~ /^[A-Z]+$/)) {rmdir $Name or die$!};

  if ((-d $Name)) {print "$Name\n"}                     

-----Original Message-----
From: Craig Moynes/Markham/IBM [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 10, 2001 9:02 AM
To: Porter, Chris
Cc: '[EMAIL PROTECTED]'
Subject: Re: Directories


> Calling perl gurus,
> Hello,  help please!!!  Looking to delete empty directories, I have a
script
> for that but if the directories have files in them, it dies.  Either can
I
> add some type of script to delete them also or can I just avoid them all
> together and just delete the empty ones.  Any help would be much
> appreciated.  Thank you.
> P.S.  All directories are capital letters, that's how I call them.  All
> lowercase needs to stay in directory.  Thanks again.

I am having some difficulty understanding your question.
If you just want to modify this script so that it does not die if the
directory contains files change the following:

[snip]
>    if ((-d $Name) and ($Name =~ /^[A-Z]+$/)) {rmdir $Name or die $!};
[snip]
Change this line to:
if ((-d $Name) and ($Name =~ /^[A-Z]+$/)) {rmdir $Name};

Its not pretty or elegant but it solves your immediate problem.
A better solution may be to enter each directory within "." and if there
are more than two entries (. and ..)
then you cannot remove this directory.



-----------------------------------------
Craig Moynes
[EMAIL PROTECTED]


Reply via email to