Macro to indicate directories in filenames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raphfrk

    Macro to indicate directories in filenames

    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%sfil ename", MACRO );

    Alternatively, is there a clean way to do it ?
  • Ian Collins

    #2
    Re: Macro to indicate directories in filenames

    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%sfil ename", MACRO );
    >
    Alternatively, is there a clean way to do it ?
    Yes, use '/', windows compilers accept both forms.

    --
    Ian Collins.

    Comment

    • Richard Heathfield

      #3
      Re: Macro to indicate directories in filenames

      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%sfil ename", 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

      Comment

      • raphfrk

        #4
        Re: Macro to indicate directories in filenames

        On Mar 28, 10:59 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
        Alternatively, is there a clean way to do it ?
        >
        If your targets are Windows and Unix, just use the / separator
        cool, thanks

        Comment

        • Mark McIntyre

          #5
          Re: Macro to indicate directories in filenames

          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.dir 2]filename.ext;ve rsion

          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 >

          Comment

          • Eric Sosman

            #6
            Re: Macro to indicate directories in filenames

            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%sfil ename", MACRO );
            >
            Alternatively, is there a clean way to do it ?
            Anything that can produce

            SYS$DISK:<rootd ir.>[topdir.director y]filename.ext;-1

            suffices.

            --
            Eric Sosman
            esosman@ieee-dot-org.invalid

            Comment

            • Joe Wright

              #7
              Re: Macro to indicate directories in filenames

              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.dir 2]filename.ext;ve rsion
              >
              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 ---

              Comment

              • Keith Thompson

                #8
                Re: Macro to indicate directories in filenames

                Ian Collins <ian-news@hotmail.co mwrites:
                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%sfil ename", MACRO );
                >>
                >Alternativel y, 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_Keit h) <kst-u@mib.org>
                Nokia
                "We must do something. This is something. Therefore, we must do this."
                -- Antony Jay and Jonathan Lynn, "Yes Minister"

                Comment

                • Antoninus Twink

                  #9
                  Re: Macro to indicate directories in filenames

                  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.dir 2]filename.ext;ve rsion
                  >>
                  >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?

                  Comment

                  Working...