Thread: directory

    #1
  1. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    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. #2
  3. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    If you're on a *nix box, just use:
    #########
    $dir = `pwd`;
    #########
    "pwd" is the system command that lists the current directory.
  4. #3
  5. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    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.
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    $dir = "/home";
    $new_dir = chdir($dir);
  8. #5
  9. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    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.
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>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";

  12. #7
  13. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    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!)
  14. #8
  15. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    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?
  16. #9
  17. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    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.
  18. #10
  19. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    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.

IMN logo majestic logo threadwatch logo seochat tools logo