LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-18-2012, 10:35 PM   #1
MidwestProduct
LQ Newbie
 
Registered: Sep 2012
Posts: 6

Rep: Reputation: Disabled
Opening a file when you don't know the filepath...


I am working on a C++ program that involves manipulating a specific .exe file using system calls. I can hard-code a specific filepath into my program and get it to work in my directory on my terminal, but I need to send it to another user who will have a completely different directory setup from mine. How can I still find this .exe file?

For example, my file is going to be in /root/user/MidwestProduct/test.exe, but on his computer it could be under /home/eng/programs/linux/test.exe, and I would still need the program to work even though the files are in different locations.
 
Old 10-19-2012, 02:30 AM   #2
everest40
Member
 
Registered: Jul 2008
Distribution: Ubuntu $LATESTVERSION
Posts: 168

Rep: Reputation: 67
Is this user likely to know where the file is? If so, you could have your program ask about it. Otherwise, all I can think of is a folder-by-folder search. To make the search faster, maybe make it possible to exclude specific folders (i.e. slow network drives), and do try some of the more likely locations first. For example, you might have the program look in /usr/bin, /usr/local/bin, and /home/username/bin (common locations for executable binaries) before searching the rest of the computer.
 
Old 10-19-2012, 06:16 AM   #3
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Rep: Reputation: Disabled
Is this program being used in the console?

why don't you just make the program a command line argument.
Code:
int main(int argc, char** argv){

  if (!argv[1]){
      std:cout << "Filename?"<<endl;
  }
  else{
  
  // your program where argv[1] is the first space deliminated text after the filename 
  

  return 0;
}
Thats some pretty weak skeleton code but it gets the job done. I recommend boost libraries if you want to make it more robust without writing a lot of additional code.
 
Old 10-19-2012, 07:42 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
commandline arguments are the way to go in my opinion, even for a GUI program; let the user specify the full path to 'test.exe'. If he/she does not know where it is, there are several ways to find it ('find' being the most obvious one).

Once it's found, a script can be used to start the program with the argument. It makes it hard-coded, but it's easier to modify a script than a binary file
 
Old 10-23-2012, 02:01 PM   #5
MidwestProduct
LQ Newbie
 
Registered: Sep 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Is there someway that I can do a system call for pwd, and pipe that result and append the filename to create the target filepath?
 
Old 10-24-2012, 06:22 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
getcwd() from your code?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash: Return next-to-lowest directory in a filepath? gldearman Programming 3 03-03-2012 02:16 PM
[SOLVED] get full filepath from filename ted_chou12 Linux - Newbie 5 11-13-2011 09:33 AM
curl certificates being refused, possible filepath issue JDska55 Linux - Newbie 3 07-13-2009 07:18 PM
Long file names on Linux file server jumbled when opening on 16-bit PC program. brandonhughesj General 3 03-04-2009 07:53 AM
how to get absolute filepath from filedescriptor appas Programming 1 07-27-2004 10:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration