Need to move up a directory...silly question


J

John

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.
 
Ad

Advertisements

K

Kris Wempa

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.
 
Ad

Advertisements

J

John

Kris Wempa said:
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 said:
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top