User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,101 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,208 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 129 | Replies: 1
Reply
Join Date: Dec 2007
Posts: 10
Reputation: nu2cpp is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
nu2cpp nu2cpp is offline Offline
Newbie Poster

BCB6 File Folder position and creation

  #1  
May 22nd, 2008
Hi,

I am developing my program on a different machine but then I take the executable to a different machine to run. The program gets data over the serial port that I write to a file for later analysis. My problem is that when I run the program on the second computer I have to go and change the file folder name where the data will be saved. This is not a big deal but problem comes in if I forget to change the folder/file name, then no data is saved. I am wondring if it is possible to do

1.) Figure out the file path where the executable is sitting as soon as the program runs
2.) and then based on that file path create another folder in that location for the data file.

Let me know if all this makes sense or not. Any help will be appreciated and thanks in advance.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2006
Location: Canada
Posts: 4,504
Reputation: John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light 
Rep Power: 17
Solved Threads: 275
Moderator
Featured Blogger
John A's Avatar
John A John A is offline Offline
Vampirical Moderator

Re: BCB6 File Folder position and creation

  #2  
May 22nd, 2008
Several ways to do it, depending on how you run the program:

- If you're using relative paths in your program, they will always be relative to the current working directory. For example, if you always run your executable from the current working directory, you could find the right location relative to that.

- If you run the executable from some arbitrary location, argv[0] will always refer to the command that was used to run it. This means that if the current working directory were / and I wanted to run a program in my home folder, I might use something like /home/john/program . argv[0] would then contain /home/john/program (However, if I did cd; ./program , argv[0] would only contain ./program ).

- You can get the current working directory on a Unix-like system with getcwd(), and with GetCurrentDirectory() on a Windows system.
tuxation.com - Linux articles, tutorials, and discussions
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:39 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC