Adam Turoff on Tue, 21 May 2002 15:25:06 -0400 |
----- Forwarded message ----- To: "Kyle R . Burton" <mortis@voicenet.com> Cc: phl@lists.pm.org Subject: Re: rm -rf and mkdir -p modules? Date: Tue, 21 May 2002 11:19:37 -0400 From: Mark-Jason Dominus <mjd@plover.com> > Anyone know of pre-existing CPAN Modules that can do the equivalent of > mkdir -p and rm -rf in a platform independant way? You ought to be able to build rm-rf atop of File::Find in a few minutes. I don't know anything about mkdir-p modules, but for the pat few years I've been using this function: sub mkdirp { my ($dir, $mode) = @_; my $pdir = ''; my @components = split(/\//, $dir); foreach $c (@components) { $pdir .= $c . '/'; next if -d $pdir; if (-e $pdir) { warn "File `$dir' already exists, but is not a directory! Fixing.\n"; rename $file, "TMP.$$"; mkdir $file; rename "TMP.$$", "$file/$default_filename"; } else { my $pdirp = $pdir; chop $pdirp; my $rc = mkdir $pdirp, $mode; unless ($rc) { next if $! =~ /exists/; warn "Couldn't make directory `$pdirp': $!. Skipping.\n"; return undef; } } } return 1; } You'll probably want to make some changes here. For example, you'll want to get rid of the $default_filename stuff, and you'll probably want to replace the 'split' with a call into File::Spec::splitpath for portability, and the unless (mkdir) { next if $! =~ /exists/ } with next if -d; unless (mkdir). Hope this helps. ----- End forwarded message ----- **Majordomo list services provided by PANIX <URL:http://www.panix.com>** **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|