Thread: About current working directory

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    About current working directory

    Hello everyone,


    If I create a file (whose name is "foo") using constant string "./foo", I am wondering under which directory should file foo be created, i.e. what/where is the current '.' directory? I think it should be current working directory, which could be get and set by Linux API getcwd/chdir?

    For example, if I use Linux API chdir to change current working directory to /temp, the file foo will be created under /temp. Is my understanding correct?


    thanks in advance,
    George

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yes.

    For easy things like this, you should test them out yourself. Learning by practice helps you to remember things.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks MacGyver! In the past, I am confused about two concepts,

    1. current working direcroty -- in which the man page of chdir mentioned always;
    2. . direcroty

    Are they the same thing?

    Quote Originally Posted by MacGyver View Post
    Yes.

    For easy things like this, you should test them out yourself. Learning by practice helps you to remember things.

    regards,
    George

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    [QUOTE=George2;640522]Thanks MacGyver! In the past, I am confused about two concepts,

    1. current working direcroty -- in which the man page of chdir mentioned always;
    2. . direcroty

    Are they the same thing?

    The '.' directory is a reference from a directory to itself. It's like the word "myself." The cwd is simply the directory where your program is considered to "be at." They are not quite the same thing, although '.' on its own means the current dir.

    But the dot can be used in other ways (not particularly productive ways, but nonetheless). For instance, if /x/y/z is a valid path, then /x/././y/z is a valid path, and so is /x/y/z/././., etc. In practice, the only USEFUL thing to do with dot is start with it, as in "./foo". But a bare filename (with no slashes) also means "in the current directory," so there is really no NEED for dot, at least at a programmatic level.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. windows explorer working directory
    By baccardi in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2009, 08:07 AM
  2. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  3. How to get the current directory and the file name
    By megareix in forum Windows Programming
    Replies: 6
    Last Post: 01-08-2009, 10:01 PM
  4. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM
  5. getting current working filename
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-17-2002, 03:42 PM