File manipulation

Hello all.

Is there anyway of manipulating files (similarly to copy, paste, cut, …) in QNX for use in C program? I need the files to be plain text or binaries.

Thanks.

ogr

fopen()
fread()
fwrite()
fclose()

(boring way: system(“cp file1 file2”):wink:

Yes, I know these functions but my application must work also with binary files.

so whats the problem?

Sorry, I think I explained it bad first time. What I want to do is to make an application that take some desired files from any location, copy this group of files (not the content) and paste them in any other location.
The solution of copying the content of these files and placing it in new created files in the other location can work with plain text files but not with binary files. More over, the attributes of the new files would be different from the original (date, permissions, …).

Is the option system(“cp file1 file2”) the only way?

Thanks

ogr

You want to copy group of files but not the content??? Sorry doesn’t compute. I think you also explain it bad the second time, lol!

I mean, I don’t want to use the option of opening the file (fopen), copying the content (fread), creating a new file in the destination location and writing the content previously read (fwrite, then fclose).
A possibility is to use system(“cp file1 file2”), but I wonder if exist another method of copying the file.

Thanks

ogr

What’s wrong with fopen/fread/fwrite/close or even better open/read/write/close.

I mean with system ( “cp file1 file2” ) it’s slower since a shell and cp must be spawn. It also gets complicated when dealing with errors. What if there is no space left, what if the source file doesn’t exists, what if there is a problem with permission?

After all, the program cp uses open/read/write/close ;-)

But, does it also works with compiled binary files?
And how can I maintain the attributes (date, permissions, …) of the original file in the new file?

Yes

stat() or fstat() will get the attributes. f/chown() and f/chmod() will change owner and permissions. Date is trickier. I can’t find a function for that. There must be a way, because passing -p to cp will “duplicate ownership, permissions and file dates.”

-James Ingraham
Sage Automation, Inc.
[/b]

for time check out utime, utimes or futime

Mario has the answer again! Too bad we’re not keeping score.

BTW, am I the only one that thinks “futime” is an obscense name for a function? :slight_smile:

-James

I will try with this functions.
Thanks a lot.

ogr

I still wonder about you thinking this won´t work with binary files.
Even in the manpages they talk from streams and blocks, never mentiond char or similar :slight_smile:

Under QNX there is no such concept as binary and text files, everything is binary.

It is also possible to virtually move files using links. This does not create a 2nd copy however.