change active directory

This is a discussion on change active directory within the Linux Programming forums, part of the Platform Specific Boards category; Hi.... Assume I have this directory: /opt/blabla Inside it there are: bla ( executable file ) and resource.txt ( resource ...

  1. #1
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92

    change active directory

    Hi....

    Assume I have this directory: /opt/blabla
    Inside it there are: bla ( executable file ) and resource.txt ( resource file needed by bla )
    $ cd /opt/blabla
    $ ./bla
    Everything runs fine...

    $ cd ~/
    $ /opt/blabla/bla
    Error: cann't find resource.txt

    or
    $ ln -s /opt/blabla/bla /usr/bin/bla
    $ cd ~/
    $ bla
    Error: cann't find resource.txt

    Is there anyway to set the current ( working ) directory to where the binary live????? I mean in bla code anyway..... So, this is part of bla source code:

    Code:
    String file = "resource.txt";
    
    //how to set the working directory to where the binary live.....
    
    LoadTheFile( file );
    Hardcode path is not an option....

    Thank you....
    Last edited by gandalf_bar; 03-28-2005 at 07:52 AM.
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  2. #2
    customized user title!
    Join Date
    Mar 2005
    Posts
    24
    You can use chdir() to change directories. If you don't want to hardcode in the directory, you can have it take it in as an command line argument.

  3. #3

  4. #4
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to tell if a file or directory
    By swappo in forum C++ Programming
    Replies: 4
    Last Post: 07-07-2009, 11:57 AM
  2. Replies: 2
    Last Post: 11-08-2002, 03:22 AM
  3. Getting back to the top of the directory
    By samGwilliam in forum Linux Programming
    Replies: 2
    Last Post: 02-25-2002, 04:49 PM
  4. Directory Existance
    By bradm in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2002, 08:50 AM
  5. Replies: 2
    Last Post: 09-04-2001, 03:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21