July 17th, 2000, 11:36 AM
-
does anybody know a simple way to set a scalar variable to whatever the partent direcotry is? For example, say that I am in /home/user and I want $dir to be /home
I was trying `cwd() ..` but that is not doing the trick, any suggestions?
July 17th, 2000, 01:04 PM
-
If you're on a *nix box, just use:
#########
$dir = `pwd`;
#########
"pwd" is the system command that lists the current directory.
July 18th, 2000, 12:12 AM
-
I am familiar with that, but I am trying to go one directory higher (hence the ..) so if I am in /home/user, i want /home to be in the scalar variable.
July 18th, 2000, 04:12 AM
-
$dir = "/home";
$new_dir = chdir($dir);
July 18th, 2000, 08:28 AM
-
right, I get that, but I was using /home as an example. It could be any directory, like /usr/local or /var/spool so the only solution I can come up with is to parse the string where the "/" dilimeters are.
July 18th, 2000, 09:28 AM
-
>>to whatever the partent direcotry is?
Oops, I didn't really read your original message. But still, I am not sure what exactly are you trying to do with that, if you could give me the exact purpose, there should be many alternative ways to do it.
Here is an example:
#!/usr/local/bin/perl
print "Content-type: text/htmlnn";
$script_url = $ENV{'SCRIPT_FILENAME'};
($current_dir = $script_url) =~ s%/[^/]+$%%;
($up_dir = $current_dir) =~ s%/[^/]+$%%;
print "Current Directory: $current_dir<br>n";
print "Up One Level: $up_dir<br>n";
July 18th, 2000, 09:30 AM
-
I know there's an easier way to do it, but right now my mind is drawing a blank :P. The only thing I can think of is to push and array with each value (split them up at every "/"). Then pop the last value, join the rest back together with the "/"'s and there ya go.
I know that you can search through it and do it easier somehow, but I'm drawing a blank (to damn early!)
July 18th, 2000, 09:39 AM
-
To be more precise:
#!/usr/local/bin/perl
print "Content-type: text/htmlnn";
$script_url = $ENV{'SCRIPT_FILENAME'};
($up_dir = $script_url) =~ s%/[^/]+/[^/]+$%%;
print "Up One Level: $up_dirn";
I am still not sure what you are trying to do. Like, is there any index.html at up one level?
July 18th, 2000, 09:55 AM
-
freebsd--
your solution worked. thanks a bunch. What I was basically trying to do was emmulate the user's home directory so they can move to different files and such. The plug in script I am working on runs on a strange daemon I created...but thanks again for the help. Basically things were not working the same between Netscape and IE.
July 18th, 2000, 10:00 AM
-
Well, cool!
I asked for more info cuz should it be ran from command line, that could be a totally different script. Like "cd ~/public_html", but it isn't the case here.