Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] create the folder using perl..

Expand Messages
  • Paul Archer
    ... True, true. But I couldn t resist. 8-) ... And yet, amazingly enough, I ve never asked your mom how she spells your name... Paul ... My New Year s
    Message 1 of 7 , Jan 6, 2004
    • 0 Attachment
      4:03pm, merlyn@... wrote:

      > >>>>> "Paul" == Paul Archer <tigger@...> writes:
      >
      > Paul> <randal>'perldoc perlfunc' and search for directory</randal>
      >
      > Unfair... I said more than that. :)
      >
      True, true. But I couldn't resist. 8-)

      > At least you spelled my name as my mom does this time.
      >
      And yet, amazingly enough, I've never asked your mom how she spells your
      name...

      Paul



      --------------------------------------
      My New Year's Resolution is 1280x1024!
      --------------------------------------
    • Hans Ginzel
      ... Here is a subroutine which is ekvivalent to shell s mkdir -p: sub CreateDir { my $dir = shift or return undef; my @path=(); while (not -d $dir) { #
      Message 2 of 7 , Jan 7, 2004
      • 0 Attachment
        On Wed, Jan 07, 2004 at 10:59:34AM +1100, Bhargava, Deepesh wrote:
        > how do we use perl to check if a folder exists, if the folder exist,
        > then do not create a folder. however if the folder does not exist, then
        > create the folder.

        Here is a subroutine which is ekvivalent to shell's mkdir -p:

        sub CreateDir {
        my $dir = shift or return undef;
        my @path=();
        while (not -d $dir) { # odlupuj od konce adresáře
        if ($dir =~ s#(.*) ([\/\\] [^\/\\]+) [\/\\]? $#$1#x) {
        unshift @path, $2;
        } else {
        if ($dir ne "") { unshift @path, $dir; $dir=""; }
        last;
        }
        }
        mkdir $dir .= $_, 0777 or
        warn("$CmdName: Cannot create directory `$dir': $!.\n"), return 0
        for @path;
        return 1;
        }

        Best regards

        Hans Ginzel
      • merlyn@stonehenge.com
        ... Hans Here is a subroutine which is ekvivalent to shell s mkdir -p: Hans sub CreateDir { [long code deleted] And here s a much shorter and more
        Message 3 of 7 , Jan 7, 2004
        • 0 Attachment
          >>>>> "Hans" == Hans Ginzel <hans@...> writes:

          Hans> Here is a subroutine which is ekvivalent to shell's mkdir -p:

          Hans> sub CreateDir {

          [long code deleted]

          And here's a much shorter and more portable one:

          use File::Path; # part of the core, no CPAN required
          mkpath("/some/directory/path", 1, 0755);

          Please. Most common operations have already been written. If you're
          writing more than five lines of code, or copying them from another
          program, THINK people THINK. Most likely, it's already been done and
          wrapped in a library for you!

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
          See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
        Your message has been successfully submitted and would be delivered to recipients shortly.