473,382 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.
Feb 7 '06 #1
14 6401
**--> 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...)
Feb 7 '06 #2
**--> 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...)
Feb 7 '06 #3
**--> 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.
Feb 7 '06 #4
**--> 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
Feb 7 '06 #5
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)
Feb 7 '06 #6
In article <ds**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@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?).

Feb 8 '06 #7
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.
Feb 8 '06 #8
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)
Feb 8 '06 #9
"**--> That Guy Downstairs <--**" <at*****@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.
Feb 8 '06 #10
"**--> That Guy Downstairs <--**" <at*****@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.

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.
Feb 8 '06 #11
**--> 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).

Feb 8 '06 #12
On 7 Feb 2006 18:18:06 -0800, "Old Wolf" <ol*****@inspire.net.nz>
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/~a...FAQ-acllc.html
Feb 8 '06 #13

"**--> That Guy Downstairs <--**" <at*****@yahoo.com> wrote in message
news:Iu********@news.boeing.com...
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
Feb 8 '06 #14
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

Feb 21 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Janina Kramer | last post by:
Hi! I'm working on a project that has to be portable (Windows, Linux, Unix (IDE is VisualC++) ). What I need is the list of files in a certain directory (+subdirs), but I also need to know some...
5
by: Henri Schomäcker | last post by:
Hi folks, I have a quite big class, which I want to use on UNIX-like systems and on win32. Until now, everything is absolutely portable. But now I need to read a directory and use the os...
13
by: James Harris | last post by:
Hi, Can someone recommend a book that will teach me how to approach C programming so that code is modularised, will compile for different environments (such as variations of Unix and Windows),...
10
by: Jason Curl | last post by:
Dear C group, I'm very interested in writing portable C, but I only have GNU, Sparc and Cygwin to compile on. What I find is the biggest problem to writing portable C is what headers to...
10
by: emmitsuks | last post by:
Can I compile C source in an PC editor like Miracle, build it, and then take that .exe over to Unix and run it there? Is there a preferred group for beginners such as myself to join?
9
by: collection60 | last post by:
I've been developing some Unix based shell tools. They work fine on Linux and MacOSX. I want to compile them on Win32. But I can't get hash_map to compile. I tried downloading stl (and...
7
by: Kristan | last post by:
Hi there, quick question, how would I retrieve a list of files in ANSI C in a purely platform independent way? Any pointers would be great! thanks Kristan
12
by: Antonio Maschio | last post by:
Hi, I need help. I want to read text files contained into a directory, but my program is unaware of how many files are contained into. In bash there's something similar to (figure out) for i...
69
by: Bill Reid | last post by:
This is how I handle a check that the last character of a text file is a newline: /* checks if newline is last character of text file */ unsigned check_text_file_newline_termination(FILE...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.