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

    chdir? Something like cd .. would be nice

    Thank you.
    John, Sep 25, 2003
    1. Advertisements

  2. John

    Kris Wempa Guest

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


    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

    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.
    Kris Wempa, Sep 25, 2003
    1. Advertisements

  3. John

    John Guest

    Great! Thanks very much Kris.
    John, Sep 25, 2003
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.