Silly question...move up a directory...

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

D Borland

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

You got it chdir

chdir '/home/john/scripts/' or die "Can't cd to /home/john/scripts/: $!\n";


Dagmar
 
J

John

D Borland 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

You got it chdir

chdir '/home/john/scripts/' or die "Can't cd to /home/john/scripts/: $!\n";


Dagmar

Dagmar,
Thanks. But if the script does not automatially know which directory it's
in, would I need to pass the full path to it first, then sed it to drop the
last directory and then use chdir on the remaining part from sed? Seems
awfully complicated for such a simple task... :(

Using your example, if the script does not know it's in home/john/scripts/
but I need to move up to home/john, then would I need to use the full path +
sed combo outlined in my first paragraph?
 
G

Gregory Toomey

It was a dark and stormy night, and John managed to scribble:
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.

chdir '..';

gtoomey
 
D

Dan Rawson

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

You got it chdir

chdir '/home/john/scripts/' or die "Can't cd to /home/john/scripts/:
$!\n";


Dagmar


Dagmar,
Thanks. But if the script does not automatially know which directory it's
in, would I need to pass the full path to it first, then sed it to drop the
last directory and then use chdir on the remaining part from sed? Seems
awfully complicated for such a simple task... :(

Using your example, if the script does not know it's in home/john/scripts/
but I need to move up to home/john, then would I need to use the full path +
sed combo outlined in my first paragraph?
John -

===============
use Cwd;

my $currdir = getcwd();
chdir '..';
.....
chdir $currdir;
===============

perldoc Cwd

Dan
 
D

D Borland

Dagmar,
Thanks. But if the script does not automatially know which directory it's
in, would I need to pass the full path to it first, then sed it to drop the
last directory and then use chdir on the remaining part from sed? Seems
awfully complicated for such a simple task... :(

Using your example, if the script does not know it's in home/john/scripts/
but I need to move up to home/john, then would I need to use the full path +
sed combo outlined in my first paragraph?


Truthfull depends on exactly what your requirements are, i'm fairly new to
perl myself so my suggestion would probably be to move up a directory you
could just do

chdir '..' or die "$!\n";

to move through the directory you could always use 'opendir' and 'readdir'
to find new directories to explore - see perlfunc man for these functions.

But like i said i'm fairly new to perl and i haven't really thought about it
too much as i'm at work at the moment, but i'm sure there will be something
on CPAN or already in perl in to this better.

Dagmar
 
J

John

D Borland said:
path


Truthfull depends on exactly what your requirements are, i'm fairly new to
perl myself so my suggestion would probably be to move up a directory you
could just do

chdir '..' or die "$!\n";

to move through the directory you could always use 'opendir' and 'readdir'
to find new directories to explore - see perlfunc man for these functions.

But like i said i'm fairly new to perl and i haven't really thought about it
too much as i'm at work at the moment, but i'm sure there will be something
on CPAN or already in perl in to this better.

Dagmar

Thanks very much guys! I knew it had to be simple...
 
J

John

Gregory Toomey said:
It was a dark and stormy night, and John managed to scribble:
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.

chdir '..';

gtoomey

Thanks Greg.
 
P

Peter Sundstrom

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

BING! You have earned yourself an entry in the Perl SAQ :)

http://www.ginini.com/perlsaq.html
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top