Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Q: portable way copy files using C on Unix an Windows -- dirent or similar (http://www.velocityreviews.com/forums/t441219-q-portable-way-copy-files-using-c-on-unix-an-windows-dirent-or-similar.html)

**--> That Guy Downstairs 02-07-2006 06:51 PM

Q: portable way copy files using C on Unix an Windows -- dirent or similar
 
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.



Nelu 02-07-2006 08:20 PM

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 02-07-2006 08:23 PM

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...)

Flash Gordon 02-07-2006 08:25 PM

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.

Default User 02-07-2006 09:41 PM

Re: Q: portable way copy files using C on Unix an Windows -- dirent or 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.


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

Richard Heathfield 02-07-2006 10:01 PM

Re: Q: portable way copy files using C on Unix an Windows -- dirent or similar
 
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)

Flash Gordon 02-07-2006 11:27 PM

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.

Kenny McCormack 02-07-2006 11:50 PM

Re: Q: portable way copy files using C on Unix an Windows -- dirent or similar
 
In article <dsb5ar$r1j$1@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <invalid@invalid.invalid> 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?).


Richard Heathfield 02-08-2006 12:24 AM

Re: Q: portable way copy files using C on Unix an Windows -- dirent or similar
 
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)

SM Ryan 02-08-2006 12:24 AM

Re: Q: portable way copy files using C on Unix an Windows -- dirent or similar
 
"**--> That Guy Downstairs <--**" <atf_eng@yahoo.com> 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.


All times are GMT. The time now is 12:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.