-
Copying File Manualy
Hello.
I tried to make a function that will make a copy of a file:
Code:
sFile sfFile;
sfFile.chFile=new CH[strlen(chFile)*sizeof(CH)];
memcpy(sfFile.chFile,chFile,strlen(chFile)*sizeof(CH));
sfFile.hFile=CreateFile(chFile,FILE_ALL_ACCESS,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(sfFile.hFile == INVALID_HANDLE_VALUE)Log("Invalid Handle on CreateFile");
sfFile.dwSize=GetFileSize(sfFile.hFile,NULL);
sfFile.uchData=new unsigned char[sfFile.dwSize];
if(ReadFile(sfFile.hFile,sfFile.uchData,sfFile.dwSize,&sfFile.dwSizeRead,0)==0)Log("Erro on Reading FIle");
FILE *store_point;
store_point=freopen("copy.exe","w",stdout);
for(int i=0;i<sfFile.dwSize;i++){
cout<<sfFile.uchData[i];
}
Where the structure is:
Code:
typedef struct sFile{
unsigned char *uchData;
CH *chFile;
HD hFile;
DW dwSize;
DW dwSizeRead;
};
Ch=char
Basicly teh output i get is close to the right one, it is 1 kb over the size but the file is no longer executable, if i try to copy an executable file.
I don't want to use winapi for copying files......
Anyways, any ideas where i made a mistake?
Thx alot in advance
-
Re: Copying File Manualy
i understand u dont want to use winpai to copy the file, but what about
Code:
system("copy filename1 filename2").
?
if i helped dont forget to rate :-)
Cheers
-
Re: Copying File Manualy
btw if you using ::CreateFile(..) why not using ::CopyFile(..)??
Cheers
-
Re: Copying File Manualy
i just wanan make some changes to teh file->compress it, but i need to be able to output teh file.
so any ideas where i made a mistake.
and thx for your answers and alt solutions :D
-
Re: Copying File Manualy
If text files seem to be copied OK, and binary files fail to get copied, make sure that you open your new file in binary mode, and not text mode. If you are using defaults, check what they are.
Hob
-
Re: Copying File Manualy
I'm not familiar with any of the windows API file handling routines,
but typically the problem you describe occurs when the output
file is not opened in binary mode.
-
Re: Copying File Manualy
thx alot i asked the question in winapi section about the mode, the msdn does not specify any of this info.
:D