| terryeverlast (25) | |||
is there a way to open and read a file than write the same file but in a different name maybe?
running it makes no files... | |||
|
Last edited on
|
|||
| webJose (2947) | |
|
You use CreateFile() to open an existing file. Then use ReadFile() or ReadFileEx() to read the contents. Finally create or overwrite the destination file with a different call to CreateFile() and then use WriteFile() on it to write whatever needs writing. Does that help? | |
|
|
|
| terryeverlast (25) | |
| read below... | |
|
Last edited on
|
|
| terryeverlast (25) | |||
here is win32 same thing but when i pressa button
the file comes out 0 BYTES | |||
|
Last edited on
|
|||
| terryeverlast (25) | |
| The file it creates says "is not a valid win32 application"..and it is 0 bytes | |
|
|
|
| closed account (DSLq5Di1) | |
Is the path of szFileTitle correct? you've used CreateFile() with OPEN_ALWAYS, meaning if the file doesn't exist, it will be created.. resulting in a 0 byte file.I get the impression you only wish to copy the file, see:- http://msdn.microsoft.com/en-us/library/windows/desktop/aa363851 | |
|
|
|
| webJose (2947) | |
|
Well, unless you are reading an executable file of just 256 bytes or less, your reading part is wrong. You normally read repeatedly until you reach the end of the file. Usually a single call to ReadFile() is never enough unless you are willing to store the entire file contentes in RAM, which is usually never done. Also note that you should be calling CloseHandle() on the handles obtained via CreateFile(). You could be seeing zero bytes because of this. CloseHandle() will, among a few other things, flush data to disk. So assuming your construction of the filename is correct (I didn't check), your problem is probably in the above. So program it like this: 1. Open the original file with CreateFile(). 2. Create the destination file with CreateFile(). 3. Start a while loop and loop while ReadFile() keeps returning TRUE. 4. In every loop iteration, write the buffer contents to the destination file. 5. Use CloseHanlde() to close the handles obtained in #1 and #2. | |
|
|
|
| andywestken (1950) | ||
Edit: I see that sloppy9 has already mentioned this!
If you want an exact copy, wouldn't it be better to use CopyFile() ?? CopyFile function http://msdn.microsoft.com/en-us/library/windows/desktop/aa363851%28v=vs.85%29.aspx Or are you heading somewhere else? | ||
|
Last edited on
|
||