Open new folder and enter it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bdan44
    New Member
    • Apr 2007
    • 11

    Open new folder and enter it

    Hi, i am trying to create a new folder and then enter the new folder. I have tried to do this but have failed on all attempts. any help would be greatly appreciated.
  • savanm
    New Member
    • Oct 2006
    • 85

    #2
    Hi,
    please show ur code here

    Comment

    • bdan44
      New Member
      • Apr 2007
      • 11

      #3
      Code:
      mkdir Test;
      use Cwd();
      $path = getcwd(); #Get the current path
      $path =~ s/\\/\//sg;
      opendir(DIR, $path) || die ("cannot open the path");
      AND

      Code:
      mkdir Sample;
      opendir(DIRHANDLE, "/Sample");
      but those didn't work. they both can create a directory but they won't enter it
      Last edited by miller; Apr 12 '07, 01:54 AM. Reason: Code Tag and Reformatting

      Comment

      • savanm
        New Member
        • Oct 2006
        • 85

        #4
        Hi,

        Still i didn't understood ur need,

        After creating the folder wt do u want to do(that means inside the newfolder)

        try the following code

        Code:
        use Cwd;
        $path = getcwd(); #Get the current path
        $path =~ s/\\/\//sg;
        print "Enter the directory name\n";
        $dir = <STDIN>;
        mkdir($dir);
        $new = $path."\/".$dir;
        opendir(DIR, $new) || die ("cannot open the path");
        mkdir("$new/hai");
        it will create a newfolder with in newfolder

        Please tel wt do u Exactly want

        Otherwise it's hard to understand(For me)
        Last edited by miller; Apr 12 '07, 01:55 AM. Reason: Code Tag and Reformatting

        Comment

        • ghostdog74
          Recognized Expert Contributor
          • Apr 2006
          • 511

          #5
          Originally posted by bdan44
          mkdir Test;
          use Cwd();
          $path=getcwd(); #Get the current path
          $path=~s/\\/\//sg;
          opendir(DIR, $path) || die ("cannot open the path");

          AND

          mkdir Sample;
          opendir(DIRHAND LE, "/Sample");

          but those didn't work. they both can create a directory but they won't enter it
          opendir opens a directory for processing by "readdir", "telldir", "seekdir", "rewinddir" and "closedir". If you want to make a directory, you should use chdir() to change to where you want to create directory, and then use mkdir().

          Comment

          • bdan44
            New Member
            • Apr 2007
            • 11

            #6
            I ended up doing it like this
            chdir('the dir i wanted') || die("couldn't do it");
            mkdir Test;
            chdir(Test) ||die("couldn't do it");

            thanks for you help though

            Comment

            Working...