Simple "rm -rf"?

Simple "rm -rf"?

am 12.01.2008 15:04:56 von Bernie Cosell

I want to nuke a temp directory. The very simplest way to do it is
system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
do it that'd be about as easy. The only thing that comes to mind is a bit
of a mess, using File::Find and unlink'ing and rmdir'ing [as appropriate]
what you run into. Tnx...

/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--

Re: Simple "rm -rf"?

am 12.01.2008 15:47:51 von Peter Scott

On Sat, 12 Jan 2008 09:04:56 -0500, Bernie Cosell wrote:
> I want to nuke a temp directory. The very simplest way to do it is
> system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
> do it that'd be about as easy. The only thing that comes to mind is a bit
> of a mess, using File::Find and unlink'ing and rmdir'ing [as appropriate]
> what you run into. Tnx...

If your program creates the directory to begin with, consider using
File::Temp:

$tempdir = tempdir( $template, CLEANUP => 1);

Create a temporary directory using the supplied template, but attempt
to remove it (and all files inside it) when the program exits. Note that
an attempt will be made to remove all files from the directory even if
they were not created by this module (otherwise why ask to clean it up?).
The directory removal is made with the rmtree() function from the
File::Path module.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Re: Simple "rm -rf"?

am 12.01.2008 18:43:59 von Abigail

_
Bernie Cosell (bernie@fantasyfarm.com) wrote on VCCXLVII September
MCMXCIII in :
?? I want to nuke a temp directory. The very simplest way to do it is
?? system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
?? do it that'd be about as easy. The only thing that comes to mind is a bit
?? of a mess, using File::Find and unlink'ing and rmdir'ing [as appropriate]
?? what you run into. Tnx...


Considering that Perl is a glue language, calling a tool to do the job
is a VERY Perlish way to accomplish your goals.

system rm => "-rf", TEMPDIR

takes just one line.



Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0 =>0=>0=>V=>IV=>0=>0
=>I=>$==-2449231+gm_julian_day+time);do{until($=<$#r){$_.=$r[$#r];$=-=$#r}for(;
!$r[--$#r];){}}while$=;$,="\x20";print+$_=>September=>MCMXCI II=>=>=>=>=>=>=>=>'

Re: Simple "rm -rf"?

am 12.01.2008 19:42:29 von Joachim Pense

Am 12 Jan 2008 17:43:59 GMT schrieb Abigail:

> _
> Bernie Cosell (bernie@fantasyfarm.com) wrote on VCCXLVII September
> MCMXCIII in :
> ?? I want to nuke a temp directory. The very simplest way to do it is
> ?? system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
> ?? do it that'd be about as easy.
.....
> Considering that Perl is a glue language, calling a tool to do the job
> is a VERY Perlish way to accomplish your goals.
>
> system rm => "-rf", TEMPDIR
>
> takes just one line.
>

And what if you need to port your code to Windows?

Joachim

Re: Simple "rm -rf"?

am 12.01.2008 19:58:06 von Abigail

_
Joachim Pense (snob@pense-mainz.eu) wrote on VCCXLVII September MCMXCIII
in :
"" Am 12 Jan 2008 17:43:59 GMT schrieb Abigail:
""
"" > _
"" > Bernie Cosell (bernie@fantasyfarm.com) wrote on VCCXLVII September
"" > MCMXCIII in :
"" > ?? I want to nuke a temp directory. The very simplest way to do it is
"" > ?? system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
"" > ?? do it that'd be about as easy.
"" ....
"" > Considering that Perl is a glue language, calling a tool to do the job
"" > is a VERY Perlish way to accomplish your goals.
"" >
"" > system rm => "-rf", TEMPDIR
"" >
"" > takes just one line.
"" >
""
"" And what if you need to port your code to Windows?


Considering that the OP said 'The very simplest way to do it is
system("rm", "-rf", TEMPDIR)', the OP either doesn't have a need to run
the script on Windows, or he has installed 'rm' on the Windows boxes he
needs to run the script on.



Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";

Re: Simple "rm -rf"?

am 12.01.2008 19:58:55 von John Bokma

Joachim Pense wrote:

> Am 12 Jan 2008 17:43:59 GMT schrieb Abigail:
>
>> _
>> Bernie Cosell (bernie@fantasyfarm.com) wrote on VCCXLVII September
>> MCMXCIII in
>> :
>> ?? I want to nuke a temp directory. The very simplest way to do it
>> is ?? system("rm", "-rf", TEMPDIR), but I'm wondering if there's a
>> perlish way to ?? do it that'd be about as easy.
> ....
>> Considering that Perl is a glue language, calling a tool to do the
>> job is a VERY Perlish way to accomplish your goals.
>>
>> system rm => "-rf", TEMPDIR
>>
>> takes just one line.
>>
>
> And what if you need to port your code to Windows?

You install rm [1]

Anyway, did the OP suggest such a thing, or you just wanted to make up a
"problem" because you don't like the solution offered? (Just curious).

[1] http://gnuwin32.sourceforge.net/
or http://unxutils.sourceforge.net/


--
John

http://johnbokma.com/mexit/

Re: Simple "rm -rf"?

am 12.01.2008 20:05:43 von Charlton Wilbur

>>>>> "JP" == Joachim Pense writes:

JP> Am 12 Jan 2008 17:43:59 GMT schrieb Abigail:

>> Considering that Perl is a glue language, calling a tool to do
>> the job is a VERY Perlish way to accomplish your goals.
>>
>> system rm => "-rf", TEMPDIR
>>
>> takes just one line.

JP> And what if you need to port your code to Windows?

If you *do* need to port your code to Windows, you fix it then.
That's what "porting" means.

If you never need to port your code to Windows, the simpler solution
saves you programmer time. If you think you *may* need to port your
code to Windows *someday*, you put in a comment that says

# TODO: this won't work on Windows

and get on with your life.

Charlton


--
Charlton Wilbur
cwilbur@chromatico.net

Re: Simple "rm -rf"?

am 13.01.2008 00:14:03 von xhoster

Joachim Pense wrote:
> Am 12 Jan 2008 17:43:59 GMT schrieb Abigail:
>
> > _
> > Bernie Cosell (bernie@fantasyfarm.com) wrote on VCCXLVII September
> > MCMXCIII in
> > : ??
> > I want to nuke a temp directory. The very simplest way to do it is ??
> > system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish
> > way to ?? do it that'd be about as easy.
> ....
> > Considering that Perl is a glue language, calling a tool to do the job
> > is a VERY Perlish way to accomplish your goals.
> >
> > system rm => "-rf", TEMPDIR
> >
> > takes just one line.
> >
>
> And what if you need to port your code to Windows?

Then do it.

What if you want to port your code to Java? What if I want hamburger
for lunch?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Re: Simple "rm -rf"?

am 13.01.2008 00:51:34 von John Bokma

xhoster@gmail.com wrote:

> What if you want to port your code to Java? What if I want hamburger
> for lunch?

And what if you don't? Questions, questions. And those don't get your
tempdir cleaned :-)

--
John

http://johnbokma.com/

Re: Simple "rm -rf"?

am 13.01.2008 16:32:59 von Bernie Cosell

Abigail wrote:

} Bernie Cosell (bernie@fantasyfarm.com) wrote on VCCXLVII September
} MCMXCIII in :
} ?? I want to nuke a temp directory. The very simplest way to do it is
} ?? system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
} ?? do it that'd be about as easy.

} Considering that Perl is a glue language, calling a tool to do the job
} is a VERY Perlish way to accomplish your goals.
}
} system rm => "-rf", TEMPDIR
}
} takes just one line.

I agree. I didn't mention it in the post, but I've been doing some Windows
perling recently and that's what got me thinking about it -- I wondered
*IF* [just speculating] just how much addition trouble it'd be to clean up
that temp directory *IF* I happened to need to port the pgm to Windows. For
now, of course, on Unix, just leaving the 'system' in works just fine. [in
a similar vein, I've gotten more careful about avoiding MySQL
"convenienices" and trying to go with "standard' SQL, just in case [again,
only "IF"..:o)] we changed to a different backend database].

/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--

Re: Simple "rm -rf"?

am 13.01.2008 16:33:03 von Bernie Cosell

Peter Scott wrote:

} On Sat, 12 Jan 2008 09:04:56 -0500, Bernie Cosell wrote:
} > I want to nuke a temp directory. The very simplest way to do it is
} > system("rm", "-rf", TEMPDIR), but I'm wondering if there's a perlish way to
} > do it that'd be about as easy....
}
} If your program creates the directory to begin with, consider using
} File::Temp:
}
} $tempdir = tempdir( $template, CLEANUP => 1);

Very cool: I didn't know about that! But even more to the point, poking
around in the ::Temp code revealed that File::Path has a rmtree() function
that does exactly what I was looking for [and I peeked at the code and
doing the nuking portably is quite an adventure!] Thanks for the
pointer...

/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--