fill large file efficiently and change file name...

Started by Eric4ever, April 03, 2006, 01:57:06 AM

Previous topic - Next topic

Eric4ever

I write a test program which function is search all the files in the chosen directory and sub-directory and to fill the files with zero, it works well but it's inefficient when fill the large files(100M or large), how can I set the NumberOfBytesToWrite in WriteFile to make it efficiently or how can I call different WriteFile(use different parameters) according to the file size?


szSize    equ  1048576     ; It compiles error but 1024 is OK
szZero    BYTE    szSize  dup  (?)
invoke  WriteFile,hFile,addr szZero,szSize,addr BytesWritten,0

szSize    equ  1048576     ; It compiles error but 1024 is OK

I use the process like this:

    CreateFile
    GetFileSize
.if eax >= 400H      ; large file
    WriteFile,hFile,ADDR szZero,szSize,ADDR BytesWritten,0     (szSize == 1024*1024)
.else                      ; small file
    WriteFile,hFile,ADDR szZero,szSize,ADDR BytesWritten,0     (szSize == 1024)



And some other questions, how can I change the file name and delete it at last after I fill the file with zero?

THX.

PBrennick

Eric4ever,
Just out of curiousity, have you ever downloaded EasyCode, the IDE?  It ican be found on this forum.  Anyway, there is a set of examples included with it.  One of them, written by Bieber, is called File Shredder.  It does exactly what you are trying to do.  I am not suggesting you just use his code.  But you can take a boo to see how he solved that problem.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Mark Jones

And Eric perhaps this will help. You can issue multiple WriteFile(s) and the data is simply concatinated. That is, you can WriteFile a 1MB chunk a hundred times to get a 100MB file. Just don't try writing a byte 104,857,600 times - WriteFile() is actually quite slow! :wink

Also you might want to consider polling for CTRL-C, ESC, or WM_CLOSE messages when dealing with really large files, so you can exit if necessary.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

asmfan

to carry out fast white operation just open a File object with special caching options specified such as using any intermediate cache to fulfil the task or not to use cache at all - write directly to disc... all these options are used with CreateFile API function.
Russia is a weird place

Mark Jones

If this is for a "file shredder" type of application, you might also consider overwriting all data in the file a few times, using a pattern of 0101010101 etc then the inverse. Or use something like Agner's pseudo-random-number generator found here to generate a buffered stream of random bytes to write to the file (it practically does this already.)

The reason why this is important is because overwriting a file once with 00's does not make it entirely erased. HDD media is magnetic and as such is prone to hysteresis or a "memory" effect. A lab could take the disk and read data from it even if it was overwritten a few times because of this. So the more times you flip the bits in the file, the less chance of reading any of it. :thumbu
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08