469,898 Members | 1,707 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Need to move up a directory...silly question

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.
Jul 19 '05 #1
2 16549

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" <no**@none.com> wrote in message
news:81*********************@news-server.bigpond.net.au...
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.

Jul 19 '05 #2

"Kris Wempa" <calmincents(NO_SPAM)@yahoo.com> wrote in message
news:bk*********@kcweb01.netnews.att.com...

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" <no**@none.com> wrote in message
news:81*********************@news-server.bigpond.net.au...
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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by andrew | last post: by
1 post views Thread by rv | last post: by
1 post views Thread by Matthew Eno | last post: by
3 posts views Thread by Arpan | last post: by
12 posts views Thread by adamurbas | last post: by
22 posts views Thread by Ramon F Herrera | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.