Thread: Opening file in directory of the running program

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    105

    Opening file in directory of the running program

    Greetings!

    I'd like to ask a quite simple question. My problem now is the following. How can I determine the location of the running program/project?
    I'd like to save data into a file, which shall be in the directory of the program. Any idea how to determine the current path?

    Thx
    Han

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Which Operating system / compiler?
    You could try looking in argv[0] which is passed to main()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    My SW is for Windows XP, I use Borland C++ Builder 5.0

  4. #4
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Well, under Windows, the default directory for storage managment is the launch directory, so, just save there.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Well since then I found the solution and it works quite well.
    My problem was that when I was calling a FileOpen function, it required the whole path to work... But I got the path acquiring function now. Thanks anyway for spending your time.

  6. #6
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    What's that FileOpen thing? I've never used such a function, I know tehre's an interface called so but it's part of the OLE Shell API and I don't think it's what you're using. However, you should use the CreateFile() function which is standard across the Windows platforms and compilers...

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    THat's right.
    I use the functions: FileCreate(), FileOpen(), FileSeek() etc.

    They are handy functions. They give you a handle (FileOpen does it), which you can use to access the specific file. I think it's the same as CreateFile() and so on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM