473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to define the working directory

Hi,
I have a code to open a file like this,

int r = open("file1", O_RDONLY, 0);

let's say the executable a.out is at <dir> and file1 is also at
<dir>, then no problem.

The problem is when my current directory is at <dir>/<sub_dir> and
file1 is at the sub directory, but a.out is still at <dir>, then when I
run this command,

../a.out

a.out always pick up <dir>/file1, instead of <dir>/<sub_dir>/file1.

Is there any way I can prevent this?

Thanks.

Jul 22 '05 #1
1 1494
"John Black" <bl***@eed.com> wrote...
Hi,
I have a code to open a file like this,

int r = open("file1", O_RDONLY, 0);

let's say the executable a.out is at <dir> and file1 is also at
<dir>, then no problem.

The problem is when my current directory is at <dir>/<sub_dir> and
file1 is at the sub directory, but a.out is still at <dir>, then when I
run this command,

../a.out

a.out always pick up <dir>/file1, instead of <dir>/<sub_dir>/file1.

Is there any way I can prevent this?


First of all, 'open' is not a standard function. Second, why not
then write

int r = open("sub_dir/file1", O_RDONLY, 0);

?

C++ does not define the concept of "directory", so you have to look in
the documentation/book/manual for programming your OS if you need to know
how to "define the working directory". It's just plain and simple beyond
the scope of the language and therefore off-topic here, sorry.

Victor
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alessandro Crugnola *sephiroth* | last post by:
hi, i have already problems using py2exe.. i'm using python 2.2, wxPython and audiere for a little mp3 player.. once I've build the exe with py2exe, when launching the application: Traceback...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
4
by: Jeff | last post by:
I feel like I should have been able to figure this out but I can't seem to find any references on this topic. It seems like my current working directory is consistently a few directories up from...
4
by: mr | last post by:
Hi i try to do something like that: #define PATH "mydir" #include "PATH/myfile.h"
11
by: Sylvia A. | last post by:
How can I define global classes in web application ? Classes can be set to session variables ? Thanks
1
by: CL4life | last post by:
I have the following problem: a program, located on drive a known drive (for example lets say drive C:) needs to execute a program on an unknown different drive (a USB device which doesn't have the...
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
2
by: Christian Blackburn | last post by:
Hi Gang, One of the properties of a shortcut is the working directory. I would like to be able to detect and use whatever working directory the shortcut specified. Can someone tell me how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.