Q: portable way copy files using C on Unix an Windows -- dirent or similar

Discussion in 'C Programming' started by **--> That Guy Downstairs, Feb 7, 2006.

  1. What files are needed to be #included to be able to copy files to a new
    directory and be portable?
    ie. use it in Unix (SGI and Linux) or Windows 2000.
    #ifdefs Ok.

    using dirent.h on SGI, but it's not working on Windows w/ VS6.0.

    Thanks.
    **--> That Guy Downstairs, Feb 7, 2006
    #1
    1. Advertising

  2. **--> That Guy Downstairs

    Nelu Guest

    Re: Q: portable way copy files using C on Unix an Windows -- direntor similar

    **--> That Guy Downstairs <--** wrote:
    > What files are needed to be #included to be able to copy files to a new
    > directory and be portable?
    > ie. use it in Unix (SGI and Linux) or Windows 2000.
    > #ifdefs Ok.
    >
    > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.
    >
    > Thanks.
    >
    >

    There's no standard way to do that. You may be able to use
    gtk+ or something similar to do that in C (or QT/wxWidgets
    for C++).
    The standard C has no idea of what a directory is, even.

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
    Nelu, Feb 7, 2006
    #2
    1. Advertising

  3. **--> That Guy Downstairs

    Nelu Guest

    Re: Q: portable way copy files using C on Unix an Windows -- direntor similar

    **--> That Guy Downstairs <--** wrote:
    <snip>
    > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.


    This is POSIX. It's not supposed to work on Windows. However,
    you can compile the sources on Windows using mingw or
    cygwin and it will work. I'm not sure how the dependency
    works under those, though.

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
    Nelu, Feb 7, 2006
    #3
  4. **--> That Guy Downstairs

    Flash Gordon Guest

    Re: Q: portable way copy files using C on Unix an Windows -- direntor similar

    **--> That Guy Downstairs <--** wrote:
    > What files are needed to be #included to be able to copy files to a new
    > directory and be portable?
    > ie. use it in Unix (SGI and Linux) or Windows 2000.
    > #ifdefs Ok.
    >
    > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.


    The C standard knows nothing about directories, so you can't do this in
    standard C which is the topic of this group.

    I would recommend you write a POSIX routine for the POSIX like systems
    (including Linux) and a Windows routine for Windows, then set up your
    build systems so that the appropriate routine is built on each system.
    Isolate all such routines from the rest of your code, then at least the
    bulk of your code is common and portable.

    The details of the specific routines, and how to configure your build
    environments, are off topic here.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Feb 7, 2006
    #4
  5. **--> That Guy Downstairs

    Default User Guest

    **--> That Guy Downstairs wrote:

    > What files are needed to be #included to be able to copy files to a
    > new directory and be portable? ie. use it in Unix (SGI and Linux) or
    > Windows 2000. #ifdefs Ok.


    The only really portable way is to open the original for reading, open
    the destination for writing, and copy the data. There are no facilities
    for creating directories though, so if by "new directory" you mean one
    that you've just made that may not work either

    Anything else is implemenation-specific.



    Brian
    Default User, Feb 7, 2006
    #5
  6. Flash Gordon said:

    > **--> That Guy Downstairs <--** wrote:
    >> What files are needed to be #included to be able to copy files to a new
    >> directory and be portable?
    >> ie. use it in Unix (SGI and Linux) or Windows 2000.
    >> #ifdefs Ok.
    >>
    >> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.

    >
    > The C standard knows nothing about directories, so you can't do this in
    > standard C which is the topic of this group.


    By the same logic, the C standard knows nothing about users, groups, and
    permissions in NT domains, so I can't write a standard C program to
    generate ACL scripts for migrating users from one domain to another. And
    yet I have written just such a program.

    The "knows nothing" terminology so beloved of comp.lang.c regulars is
    woefully broken. Oxymoronically, we need a new cliche.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Feb 7, 2006
    #6
  7. **--> That Guy Downstairs

    Flash Gordon Guest

    Re: Q: portable way copy files using C on Unix an Windows -- direntor similar

    Richard Heathfield wrote:
    > Flash Gordon said:
    >
    >> **--> That Guy Downstairs <--** wrote:
    >>> What files are needed to be #included to be able to copy files to a new
    >>> directory and be portable?
    >>> ie. use it in Unix (SGI and Linux) or Windows 2000.
    >>> #ifdefs Ok.
    >>>
    >>> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.

    >> The C standard knows nothing about directories, so you can't do this in
    >> standard C which is the topic of this group.

    >
    > By the same logic, the C standard knows nothing about users, groups, and
    > permissions in NT domains, so I can't write a standard C program to
    > generate ACL scripts for migrating users from one domain to another. And
    > yet I have written just such a program.


    Yes, but a script is a file, and standard C can manipulate files. Based
    on what the OP says (mention of using dirent) he is actually reading the
    directory.

    > The "knows nothing" terminology so beloved of comp.lang.c regulars is
    > woefully broken. Oxymoronically, we need a new cliche.


    Well, if you can suggest a better phrase feel free.
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Feb 7, 2006
    #7
  8. In article <dsb5ar$r1j$-infra.bt.com>,
    Richard Heathfield <> wrote:
    ....
    >By the same logic, the C standard knows nothing about users, groups, and
    >permissions in NT domains, so I can't write a standard C program to
    >generate ACL scripts for migrating users from one domain to another. And
    >yet I have written just such a program.


    Be careful. You're posting sense in a nonsense newsgroup.
    Your fellow regulars might desert you.
    And then where will you be?

    >The "knows nothing" terminology so beloved of comp.lang.c regulars is
    >woefully broken. Oxymoronically, we need a new cliche.


    Well put.

    I also think we need a terminology that avoids the absurd statement that
    something that is obviously C, but which includes functions, etc that are
    not in the standard is "not C" (when it obviously is C - do I have to
    elaborate this any further?).
    Kenny McCormack, Feb 7, 2006
    #8
  9. Flash Gordon said:

    > Richard Heathfield wrote:
    >> Flash Gordon said:
    >>
    >>> **--> That Guy Downstairs <--** wrote:
    >>>> What files are needed to be #included to be able to copy files to a new
    >>>> directory and be portable?
    >>>> ie. use it in Unix (SGI and Linux) or Windows 2000.
    >>>> #ifdefs Ok.
    >>>>
    >>>> using dirent.h on SGI, but it's not working on Windows w/ VS6.0.
    >>> The C standard knows nothing about directories, so you can't do this in
    >>> standard C which is the topic of this group.

    >>
    >> By the same logic, the C standard knows nothing about users, groups, and
    >> permissions in NT domains, so I can't write a standard C program to
    >> generate ACL scripts for migrating users from one domain to another. And
    >> yet I have written just such a program.

    >
    > Yes, but a script is a file, and standard C can manipulate files. Based
    > on what the OP says (mention of using dirent) he is actually reading the
    > directory.


    I'm not arguing that the OP's requirement can be solved portably. I'm only
    arguing that C's "ignorance" of a subject does not, /per se/, make that
    subject off-topic.

    >
    >> The "knows nothing" terminology so beloved of comp.lang.c regulars is
    >> woefully broken. Oxymoronically, we need a new cliche.

    >
    > Well, if you can suggest a better phrase feel free.


    Nothing as terse springs to mind, alas. Unless someone comes up with a
    suitable replacement, we may simply have to accept that sometimes the
    choice is between "wrong" and "long". Of the two, I prefer "long".

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Feb 8, 2006
    #9
  10. **--> That Guy Downstairs

    SM Ryan Guest

    "**--> That Guy Downstairs <--**" <> wrote:
    # What files are needed to be #included to be able to copy files to a new
    # directory and be portable?
    # ie. use it in Unix (SGI and Linux) or Windows 2000.
    # #ifdefs Ok.
    #
    # using dirent.h on SGI, but it's not working on Windows w/ VS6.0.
    #
    # Thanks.
    #
    #
    #
    #

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    This is one wacky game show.
    SM Ryan, Feb 8, 2006
    #10
  11. **--> That Guy Downstairs

    SM Ryan Guest

    "**--> That Guy Downstairs <--**" <> wrote:
    # What files are needed to be #included to be able to copy files to a new
    # directory and be portable?
    # ie. use it in Unix (SGI and Linux) or Windows 2000.
    # #ifdefs Ok.

    You might consider something other than C, like Tcl or Perl.
    In Tcl, you can do this portably in a few dozen lines. I expect
    Perl to be as easy.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    This is one wacky game show.
    SM Ryan, Feb 8, 2006
    #11
  12. **--> That Guy Downstairs

    Old Wolf Guest

    **--> That Guy Downstairs <--** wrote:

    > What files are needed to be #included to be able to copy files to a new
    > directory and be portable?
    > ie. use it in Unix (SGI and Linux) or Windows 2000.
    > #ifdefs Ok.
    >
    > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.


    Upgrade your compiler? All the windows compilers I've ever used
    provide the common unix functions (dirent.h etc).
    Old Wolf, Feb 8, 2006
    #12
  13. **--> That Guy Downstairs

    Jack Klein Guest

    On 7 Feb 2006 18:18:06 -0800, "Old Wolf" <>
    wrote in comp.lang.c:

    > **--> That Guy Downstairs <--** wrote:
    >
    > > What files are needed to be #included to be able to copy files to a new
    > > directory and be portable?
    > > ie. use it in Unix (SGI and Linux) or Windows 2000.
    > > #ifdefs Ok.
    > >
    > > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.

    >
    > Upgrade your compiler? All the windows compilers I've ever used
    > provide the common unix functions (dirent.h etc).


    You haven't looked at quite enough Windows compilers. It's been
    absent from Microsoft's Visual C++ since at least 6.0. The features
    are quite easy to implement on top of the Win32 API, and every other
    compiler that I know of for Win32 does so.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Feb 8, 2006
    #13
  14. Re: portable way copy files using C on Unix an Windows -- dirent or similar

    "**--> That Guy Downstairs <--**" <> wrote in message
    news:...
    > What files are needed to be #included to be able to copy files to a new
    > directory and be portable?
    > ie. use it in Unix (SGI and Linux) or Windows 2000.
    > #ifdefs Ok.
    >
    > using dirent.h on SGI, but it's not working on Windows w/ VS6.0.


    I don't have a working solution for you. But, I have a place you can start.
    Doug Gwyn's libndir. The file I have is called: libndir-posix.tar.Z. It
    contains C code to add dirent and 'friends' to POSIX like OS's. You'll need
    to do some porting.


    Rod Pemberton
    Rod Pemberton, Feb 8, 2006
    #14
  15. **--> That Guy Downstairs

    S7Solutions Guest

    Hi there

    There is no one standard answer for this - it's a ocean of porting to
    do but again depends on what and how much compatibility you are
    expecting. If you want you can contact us for a free technical road map
    for porting.

    Manjunath M
    S7 Software Solutions
    Re-Defining Cross-Platform Porting & Migration
    www.S7SOlutions.com
    S7Solutions, Feb 21, 2006
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Pohlack

    sizeof(struct dirent.d_ino)

    Martin Pohlack, Sep 8, 2003, in forum: C Programming
    Replies:
    19
    Views:
    1,074
    Keith Thompson
    Sep 10, 2003
  2. Dirent.h

    , Feb 26, 2006, in forum: C++
    Replies:
    3
    Views:
    723
    Larry I Smith
    Feb 26, 2006
  3. Replies:
    9
    Views:
    513
    P.J. Plauger
    May 10, 2006
  4. eddie

    Need help with struct *** dirent ???

    eddie, Jan 10, 2009, in forum: C Programming
    Replies:
    7
    Views:
    488
    Richard
    Jan 12, 2009
  5. Sascha Wüstemann
    Replies:
    4
    Views:
    1,037
    Ike Naar
    Aug 3, 2011
Loading...

Share This Page