Directory path

C

cjw

Pl help me with this simple question.
I am using an array to store the file name,
eg. char in[] = "filename.bmp"; How can I give the directory path with
the file name?
 
A

Arthur J. O'Dwyer

Pl help me with this simple question.
I am using an array to store the file name,
eg. char in[] = "filename.bmp"; How can I give the directory
path with the file name?

char in_plus_path[] = "c:\\mystuff\\filename.bmp";
char unix_style[] = "/mystuff/filename.bmp";

What are you really trying to do?

-Arthur
 
D

Dan Pop

Pl help me with this simple question.
I am using an array to store the file name,
eg. char in[] = "filename.bmp"; How can I give the directory
path with the file name?

char in_plus_path[] = "c:\\mystuff\\filename.bmp";

"c:/mystuff/filename.bmp" looks much better as a Windows path.

Many non-Unix implementations support Unix-style paths, even if the
native convention is different.

Dan
 
K

Kris Wempa

Dan Pop said:
J. O'Dwyer said:
"c:/mystuff/filename.bmp" looks much better as a Windows path.

Many non-Unix implementations support Unix-style paths, even if the
native convention is different.

This works only on the NT/2000/XP versions of Windows. The 95/98/ME
versions do not accept the forward slashes.
 
D

Dan Pop

This works only on the NT/2000/XP versions of Windows. The 95/98/ME
versions do not accept the forward slashes.

As argument to the fopen function, such path specifications work since
MSDOS.

Dan
 
J

Joe Wright

Kris said:
This works only on the NT/2000/XP versions of Windows. The 95/98/ME
versions do not accept the forward slashes.

Not true. Even DOS 6.22 accepted forward slashes. It is COMMAND.COM
which doesn't.
 
A

Arthur J. O'Dwyer

As argument to the fopen function, such path specifications work since
MSDOS.

Depends on your implementation of fopen(), doesn't it now? ;-)
(Yes, I think whatever DOS service that was allowed forward slashes,
but it's implementation-defined whether fopen() uses the DOS services ;-)

And besides, you might want to do other things with a filename
besides open it -- like, for instance, passing it to system().
And then if system() uses COMMAND.COM, you have problems.

-Arthur
 
M

Mike Wahler

Kris Wempa said:
This works only on the NT/2000/XP versions of Windows. The 95/98/ME
versions do not accept the forward slashes.

<OT>

All of mine certainly do (my Windows side of the room
has various machines running 95B, 98SE, NT4, and XP)

</OT>

-Mike
 
K

Kris Wempa

Dan Pop said:
As argument to the fopen function, such path specifications work since
MSDOS.

Perhaps the forward slashes work for fopen(), but they don't currently work
if used in a system() call. This caused some problems in the past for a
Java applets that were trying to run certain commands based upon the
operating system. Windows 2000/NT accepted the forward slashes, but Windows
95 did NOT.
 
D

Dan Pop

Depends on your implementation of fopen(), doesn't it now? ;-)

Indeed: one can conceive an implementation accepting *only* the forward
slashes ;-) But we're talking about the *real* implementations for DOS.
(Yes, I think whatever DOS service that was allowed forward slashes,
but it's implementation-defined whether fopen() uses the DOS services ;-)

It doesn't matter, as long as all known C implementations for DOS support
it ;-)
And besides, you might want to do other things with a filename
besides open it -- like, for instance, passing it to system().
And then if system() uses COMMAND.COM, you have problems.

system() is the only standard library function where the rules are
different. But the context of the thread was <stdio.h>...

Dan
 
C

cjw

Thanks. Both versions worked. I have program files and data files in
two different directories at the same level. Is there a short form of
specifying it rather than giving the full directory path?
cjw

Arthur J. O'Dwyer said:
Pl help me with this simple question.
I am using an array to store the file name,
eg. char in[] = "filename.bmp"; How can I give the directory
path with the file name?

char in_plus_path[] = "c:\\mystuff\\filename.bmp";
char unix_style[] = "/mystuff/filename.bmp";

What are you really trying to do?

-Arthur
 
D

Dan Pop

In said:
Thanks. Both versions worked. I have program files and data files in
two different directories at the same level. Is there a short form of
specifying it rather than giving the full directory path?

You can use relative paths. If your current working directory is the
parent directory of both the data directory and the program directory,
you can use something like: "data/file001.dat" and "prog/program1.exe".

Particularly useful in relative paths on certain systems (Unix and Windows
included) is the ".." thing which stands for the parent directory. In the
context of the previous example, assume that your current working
directory is prog and you want to specify the relative path of
file001.dat: "../data/file001.dat". You can use .. multiple times, to go
further backwards: "../../../foo/bar/baz.dat".

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top