Need to move up a directory...silly question

Discussion in 'Perl' started by John, Sep 25, 2003.

  1. John

    John Guest

    Sorry, but how does one move up a directory ?

    I'm in a directory from which I called a script. Part of the script
    functionality is checking the permissions of the directory I am in. I may
    need to change the directory permissions depending on what they are. Hence,
    I need to be able to move up [and possibly down] one level of the directory
    tree.

    chdir? Something like cd .. would be nice

    Thank you.
     
    John, Sep 25, 2003
    #1
    1. Advertising

  2. John

    Kris Wempa Guest

    I'm not sure if the Perl chdir() function accepts a ".." argument. If it
    does, you can do:

    chdir("..");

    to go up a directory. If not, you will have to do something such as:

    $currdir = `pwd`; chomp $currdir; # gets current directory
    $currdir =~ s/ \/[^\/]+$//; # removes the last / and everything after it
    chdir($currdir);

    That's a very crude example where I'm not doing things like checking return
    values or making sure we are not already in the root directory. However,
    that's the general idea.


    "John" <> wrote in message
    news:81Ccb.122677$...
    > Sorry, but how does one move up a directory ?
    >
    > I'm in a directory from which I called a script. Part of the script
    > functionality is checking the permissions of the directory I am in. I may
    > need to change the directory permissions depending on what they are.

    Hence,
    > I need to be able to move up [and possibly down] one level of the

    directory
    > tree.
    >
    > chdir? Something like cd .. would be nice
    >
    > Thank you.
    >
    >
     
    Kris Wempa, Sep 25, 2003
    #2
    1. Advertising

  3. John

    John Guest

    "Kris Wempa" <calmincents(NO_SPAM)@yahoo.com> wrote in message
    news:bkuvtk$...
    >
    > I'm not sure if the Perl chdir() function accepts a ".." argument. If it
    > does, you can do:
    >
    > chdir("..");
    >
    > to go up a directory. If not, you will have to do something such as:
    >
    > $currdir = `pwd`; chomp $currdir; # gets current directory
    > $currdir =~ s/ \/[^\/]+$//; # removes the last / and everything after it
    > chdir($currdir);
    >
    > That's a very crude example where I'm not doing things like checking

    return
    > values or making sure we are not already in the root directory. However,
    > that's the general idea.
    >
    >
    > "John" <> wrote in message
    > news:81Ccb.122677$...
    > > Sorry, but how does one move up a directory ?
    > >
    > > I'm in a directory from which I called a script. Part of the script
    > > functionality is checking the permissions of the directory I am in. I

    may
    > > need to change the directory permissions depending on what they are.

    > Hence,
    > > I need to be able to move up [and possibly down] one level of the

    > directory
    > > tree.
    > >
    > > chdir? Something like cd .. would be nice
    > >
    > > Thank you.
    > >
    > >


    Great! Thanks very much Kris.
     
    John, Sep 25, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt MacDonald
    Replies:
    0
    Views:
    414
    Matt MacDonald
    Jan 30, 2008
  2. mike
    Replies:
    2
    Views:
    494
    Roedy Green
    Mar 15, 2008
  3. Eduardo78
    Replies:
    0
    Views:
    274
    Eduardo78
    Nov 3, 2005
  4. Andrew Tomazos
    Replies:
    2
    Views:
    671
    Nobody
    Dec 12, 2011
  5. John
    Replies:
    8
    Views:
    114
    Peter Sundstrom
    Sep 26, 2003
Loading...

Share This Page