|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
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? |
|
#2
|
|||
|
|||
|
If you're on a *nix box, just use:
######### $dir = `pwd`; ######### "pwd" is the system command that lists the current directory. |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||
|
|||
|
$dir = "/home";
$new_dir = chdir($dir); |
|
#5
|
||||
|
||||
|
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.
|
|
#6
|
|||
|
|||
|
>>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"; |
|
#7
|
|||
|
|||
|
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!) |
|
#8
|
|||
|
|||
|
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? |
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|