develooper Front page | perl.beginners | Postings from March 2002

RE: making parent directories

Thread Previous | Thread Next
From:
Timothy Johnson
Date:
March 5, 2002 10:58
Subject:
RE: making parent directories
Message ID:
C0FD5BECE2F0C84EAA97D7300A500D5002581047@SMILEY

I know there's an easier way, but here's one way...

unless(-e $destDir){  #check for directory creation
	my @dirs = split /\\/,$destDir;  # this was made on a Win32 system
	my $dirstring;
	foreach(@dirs){   #build directory tree if it does not exist
		$dirstring .= "$_\\";
		unless(-e $dirstring){
			mkdir $dirstring || warn "could not build part of
$dirstring!\n";
		}
	}
}

-----Original Message-----
From: zentara [mailto:zentara@highstream.net]
Sent: Tuesday, March 05, 2002 10:44 AM
To: beginners@perl.org
Subject: making parent directories


Hi,

I was writing a script in which I needed to make
a directory "at depth", without having the parent directories
created yet.  For example:

#!/usr/bin/perl
use warnings;

mkdir("1/2/3", 0777) || die "cannot mkdir 1/2/3: $!";

Is there a way to deal with this without resorting to a 
system call?

In bash it's easy,
mkdir -p 1/2/3

So is there some way perl deals with this?




-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About