Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadFile(); WriteFile(); problem - source code included

Status
Not open for further replies.

Tazor

Programmer
Dec 18, 2001
3
CA
Trying to make a program that takes an existing file, creates a new one complying with POSIX standards (so you can create it in uppercase [this is on NTFS] - yes there is a difference - windows won't let you do it, it will ask if you want to overwrite), and then copies the data of the source file into the destination (new) file.

But forget all the POSIX stuff, i can't even get this thing to copy over the file at all. When i execute the code, i get my new file, but its 0 bytes. What am i doing wrong???

SOURCE CODE:
 
Rather then doing the read and write to copy the file, and since you seem to understand the API, use CopyFile instead. Let the api do the work for you.

Matt
 
actually i was reading through the docs in the MSDN and it doesn't let you set file attributes :\ All it does is copy them over.
"File attributes for the existing file are copied to the new file. For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute"

This does not work because i have to take a file without the FILE_FLAG_POSIX_SEMANTICS attribute and copy the data over to one with the FILE_FLAG_POSIX_SEMANTICS (using createfile to open one and create another, and then readfile writefile into it...)

Oh and i am new to winapi - my friend needs this done soon and is basically giving me a crash course and i obviously don't know enuf heh.
 
Well... this is a shot in the dark but... Create a file with the POSIX attributes required. Save this file in a common place (hard code the path for now and for future stuff maybe use the registry) *lets say it is saved in C:\Attribs*

You could try:

Code:
CFile attribs;
attribs.Open("C:\\Attribs",CFile::modeReadOnly|CFile::shareDenyNone);

CFileStatus stat;
attribs.GetStatus(stat);

//COPY FILE API CALL
// open the file just copied 
CFile newFile;
newFile.Open("C:\\NewFileToGetAttributes");
CFileStatus tmp;
newFile.GetStatus(tmp);
tmp.m_attribute = stat.m_attribute;
newFile.SetStatus(tmp);[code]

I hope this works.... i have never tried this before.

Matt
 
Thanks a lot - gotta go xmas shopping for now - i'll try it when i get home. Looks more promising than something i would have thought up! Man need to get some books on the api :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top