#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    1
    Rep Power
    0

    path problem in c++ under linux


    i have some problems:

    suppose I have a directory A and it has two subdirectories B and C and I work in B. Is there a way to go back from B to A in c++?
    (under windows it works with "chdir", but under linux doesn't work)

    another problem: is there an alternative under linux for the windows' command _fullpath?

    (see eventually http://msdn.microsoft.com/library/de..._wfullpath.asp )


    thakx.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,640
    Rep Power
    4247
    >> (under windows it works with "chdir", but under linux doesn't work)
    What exactly are you trying to do. chdir() works for me just fine. This is with gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
    Code:
    #include <stdio.h>
    #include <unistd.h>
    
    int main(void) {
      FILE *fp;
      char buf[80];
    
      chdir("..");
      fp = fopen("foo.html", "r");
      if (fp == NULL) {
        fprintf(stderr, "Could not open foo.html");
        return 0;
      }
      while (!feof(fp)) {
        fgets(buf, 80, fp);
        fprintf(stdout, buf);
      }
      fclose(fp);
      chdir("tester");
      return 0;
    }
    >> another problem: is there an alternative under linux for the windows' command _fullpath?
    man getcwd
    man get_current_directory
    man getwd

    Take your pick. Note that get_current_directory() is not supported by *BSDs, only by Linux.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo