Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Macro to indicate directories in filenames

Reply
Thread Tools

Macro to indicate directories in filenames

 
 
raphfrk
Guest
Posts: n/a
 
      03-28-2008
I was wondering if there is a standard macro that will evaluate to the
directory separator character in the OS that the compiler is
targeting.

For example, in UNIX, it would be / while in windows it would be \

A filename could then be built up using

sprintf( filename , "directory%sfilename", MACRO );

Alternatively, is there a clean way to do it ?
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-28-2008
raphfrk wrote:
> I was wondering if there is a standard macro that will evaluate to the
> directory separator character in the OS that the compiler is
> targeting.
>
> For example, in UNIX, it would be / while in windows it would be \
>
> A filename could then be built up using
>
> sprintf( filename , "directory%sfilename", MACRO );
>
> Alternatively, is there a clean way to do it ?


Yes, use '/', windows compilers accept both forms.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      03-28-2008
raphfrk said:

> I was wondering if there is a standard macro that will evaluate to the
> directory separator character in the OS that the compiler is
> targeting.


There isn't, for the very simple reason that the Standard doesn't
acknowledge the existence of directories. (Some systems really, truly,
honestly don't have them. They have other ways of organising files.)

> For example, in UNIX, it would be / while in windows it would be \
>
> A filename could then be built up using
>
> sprintf( filename , "directory%sfilename", MACRO );
>
> Alternatively, is there a clean way to do it ?


If your targets are Windows and Unix, just use the / separator - it works
fine on both. (It doesn't actually work on the Windows command line for
ordinary "DOS"-style commands, but it works just fine within a C program.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
raphfrk
Guest
Posts: n/a
 
      03-28-2008
On Mar 28, 10:59 pm, Richard Heathfield <(E-Mail Removed)> wrote:
> > Alternatively, is there a clean way to do it ?

>
> If your targets are Windows and Unix, just use the / separator


cool, thanks
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      03-28-2008
raphfrk wrote:
> I was wondering if there is a standard macro that will evaluate to the
> directory separator character in the OS that the compiler is
> targeting.


Not possible. Consider that VMS uses the form

server::disk:[000000.dir1.dir2]filename.ext;version

and other OSen use even more amusing variants.

For windows and *nix, as others have pointed out, "/" is fine, windows
only pretends not to like /.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      03-28-2008
raphfrk wrote:
> I was wondering if there is a standard macro that will evaluate to the
> directory separator character in the OS that the compiler is
> targeting.
>
> For example, in UNIX, it would be / while in windows it would be \
>
> A filename could then be built up using
>
> sprintf( filename , "directory%sfilename", MACRO );
>
> Alternatively, is there a clean way to do it ?


Anything that can produce

SYS$DISK:<rootdir.>[topdir.directory]filename.ext;-1

suffices.

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Joe Wright
Guest
Posts: n/a
 
      03-29-2008
Mark McIntyre wrote:
> raphfrk wrote:
>> I was wondering if there is a standard macro that will evaluate to the
>> directory separator character in the OS that the compiler is
>> targeting.

>
> Not possible. Consider that VMS uses the form
>
> server::disk:[000000.dir1.dir2]filename.ext;version
>
> and other OSen use even more amusing variants.
>
> For windows and *nix, as others have pointed out, "/" is fine, windows
> only pretends not to like /.
>

It is the Windows command processors, command.com and cmd.exe which
demand '\' separators. The OS as far back as MSDOS 2.0 I think, is quite
happy with the '/' separator.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-29-2008
Ian Collins <(E-Mail Removed)> writes:
> raphfrk wrote:
>> I was wondering if there is a standard macro that will evaluate to the
>> directory separator character in the OS that the compiler is
>> targeting.
>>
>> For example, in UNIX, it would be / while in windows it would be \
>>
>> A filename could then be built up using
>>
>> sprintf( filename , "directory%sfilename", MACRO );
>>
>> Alternatively, is there a clean way to do it ?

>
> Yes, use '/', windows compilers accept both forms.


<OT>
If you're using it to open a file, it's probably ok. If you intend to
display it to a user, possibly a Windows user who's not aware of this
particular hidden feature of Windows, you might want to consider
going to some extra effort to use '\\'.
</OT>

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Antoninus Twink
Guest
Posts: n/a
 
      03-29-2008
On 29 Mar 2008 at 0:29, Joe Wright wrote:
> Mark McIntyre wrote:
>> raphfrk wrote:
>>> I was wondering if there is a standard macro that will evaluate to the
>>> directory separator character in the OS that the compiler is
>>> targeting.

>>
>> Not possible. Consider that VMS uses the form
>>
>> server::disk:[000000.dir1.dir2]filename.ext;version
>>
>> and other OSen use even more amusing variants.
>>
>> For windows and *nix, as others have pointed out, "/" is fine, windows
>> only pretends not to like /.
>>

> It is the Windows command processors, command.com and cmd.exe which
> demand '\' separators. The OS as far back as MSDOS 2.0 I think, is quite
> happy with the '/' separator.


That must be useful for CBF then - I think he's upgraded to MSDOS 2.0
now, hasn't he?

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing filenames in different directories Deepu Perl Misc 10 03-16-2007 04:17 PM
problem with filenames, Filenames and FILENAMES B.J. HTML 4 04-23-2005 08:13 PM
newbie wants to compile python list of filenames in selected directories anthonyberet Python 5 02-08-2005 08:10 PM
How to map Project directories to Production sub-directories Joel Finkel ASP .Net 0 09-12-2003 06:47 PM
Using virtual directories for common directories (scripts, images, styles, etc.) Jeffry van de Vuurst ASP .Net 2 07-30-2003 07:00 PM



Advertisments