buttercheese Posted January 12, 2005 Share Posted January 12, 2005 Hi together, I need a tool, that can create files of a desired size. The files should contain only zeros or random signs. It´s recommended that you can handle the filesize exactly. Taht means, that creating a file with 12345 Bytes should contain 12345 Bytes. Influencing name and suffix of the file would be fine but doesn´t really matters. Thanks a lot for all of your ideas. Cheers buttercheese Link to comment Share on other sites More sharing options...
DaLiMan Posted January 12, 2005 Share Posted January 12, 2005 U could try something like (NOT TESTED): While 1 If FileGetSize("C:\File.txt") = "12345" Then ; ; Do Something ; ExitLoop Else LogFileWrite("C:\File.txt", "0") EndIf Wend Exit Func LogFileWrite($filename, $text) While 1 If 1 = FileWrite($filename, $text) Then ExitLoop Sleep(300) Wend Return EndFunc Link to comment Share on other sites More sharing options...
DaLiMan Posted January 12, 2005 Share Posted January 12, 2005 Just tested the script and it works, but creating a file of 10000 kb took me approx. 162047 millisec. according to the Auto-It Timer. So very big files will be a problem if you don't have much time...... Here's my testing script: FileDelete("C:\File.txt") $begin = TimerInit() While 1 If FileGetSize("C:\File.txt") = "10000" Then ; ; Do Something ; ExitLoop Else LogFileWrite("C:\File.txt", "0") EndIf Wend $dif = TimerDiff($begin) MsgBox(0,"Time Difference",$dif) Exit Func LogFileWrite($filename, $text) While 1 If 1 = FileWrite($filename, $text) Then ExitLoop Sleep(300) Wend Return EndFunc Link to comment Share on other sites More sharing options...
Valik Posted January 12, 2005 Share Posted January 12, 2005 (edited) Try using a handle instead of opening/writing/closing the file every time, which is what happens when you don't specify a handle. And remove the Sleep(), or at least reduce it to like 10 ms (Probably should just remove it, though). Edited January 12, 2005 by Valik Link to comment Share on other sites More sharing options...
Tys Posted January 12, 2005 Share Posted January 12, 2005 (edited) To speed up things, first create a/some larger string(s) in memory and append that to the file, it helps to minimize disk access. Edited January 12, 2005 by Tys Link to comment Share on other sites More sharing options...
SvenP Posted January 12, 2005 Share Posted January 12, 2005 (edited) Maybe I mis-interpret the original question. But I think buttercheese ment the following: expandcollapse popupFunc FileFillRandom($Filename,$Size, $Zero) ; ; Fills a file up to given size. Zero or random bytes by flag. ; ; Arguments: ; $Filename Name of file to create ; $Size Size the file should be ; $Zero Flag: 1=fill only with zeros ; 0=fill with random characters ; ; Returns: ; -1 If file could not be created ; otherwise Number of bytes written (if successfull this should be equal to $Size) ; Dim $Counter;Just a counter Dim $fHandle;Filehandle to filename $fHandle=FileOpen($Filename,2); Open the file in write mode if $fHandle = -1 then Msgbox (0,"FileFillRandom","Error writing to file: " & $Filename) Return -1 endif For $Counter = 1 to $Size if $Zero = 1 then if not FileWrite($fHandle,chr(0)) then exitloop else if not FileWrite($fHandle,chr(Random(0,255))) then exitloop endif Next FileClose($fHandle); Close the file Return $Counter -1; Must be -1 because the for-loop has increased it. EndFunc You can call this function like this: ; Test the function FileFillRandom() Dim $Return; Just a return value $Return=FileFillRandom("C:\TESTFILE.DAT",100,0) if $Return <> 100 then MsgBox (0,"FileFillRandom Test","Error: written: " & $Return & " but expected: 100") else MsgBox (0,"FileFillRandom Test","Test 1 ok, written: " & $Return & " bytes.") endif $Return=FileFillRandom("C:\TESTFILE2.DAT",200,1) if $Return <> 200 then MsgBox (0,"FileFillRandom Test","Error: written: " & $Return & " but expected: 200") else MsgBox (0,"FileFillRandom Test","Test 2 ok, written: " & $Return & " bytes.") endif Regards, -Sven EDIT: I opened file in append (1) mode instead of overwrite (=2). Changed this now in the code. Edited January 12, 2005 by SvenP Link to comment Share on other sites More sharing options...
trids Posted January 13, 2005 Share Posted January 13, 2005 @SvenP .. I changed the "Return" line in your func as follows:; Return $Counter -1; Must be -1 because the for-loop has increased it. Return FileGetSize($FileName).. and got some interesting results: asking for a file of 1000 random bytes yields files of varying size: sometimes 992, sometimes 996, sometimes 995 etc.asking for a file of null characters yields an empty file.You might want to add 1 to the Random number generated, so as to avoid the file-termination character. Also probably explains why a non-random file is "empty" Link to comment Share on other sites More sharing options...
Insolence Posted January 13, 2005 Share Posted January 13, 2005 Also couldn't you just break the size, for example 1024, into larger chunks? Like 1000, 20, 4? I think I saw that somewhere else, but it wasn't faster. Just throwing that up in the air "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
buttercheese Posted January 13, 2005 Author Share Posted January 13, 2005 Hey tremendous, thanks alot for your feedback. :-) May I tell you some more about my idea? As I have seen, generating all the random stuff takes a lot of time. I want to use the code to erase data from HD after formatting. Getting data after formatting should be made unpossible. So, if the file is about 40GB, you can spend holidays until the job is done. ;-) The content of the file could be whatever. I just want to create a big file, write to disk, erase, create a second big file, write to disk, erase... (about 8 times) and now the HD is really cleaned and ready to become second hand instead of becoming garbage for security reasons. The selecting of the filesize should be given for leaving the needed data (if there is). Your ideas are still welcome, thanks buttercheese Link to comment Share on other sites More sharing options...
buttercheese Posted January 13, 2005 Author Share Posted January 13, 2005 (edited) Question: How about if I append files? Lets say, that I´ve got or generate 1 file with 10MB, 1 with 1MB... and so on... When the file should be f.e. 402 MB I append 40 times the 10MB file and 2 times the 1MB. Is that an idea to start, a feasable way? Cheers Buttercheese Edited January 13, 2005 by buttercheese Link to comment Share on other sites More sharing options...
Valik Posted January 13, 2005 Share Posted January 13, 2005 If this is your intention, then I'd look for some free software that already does this. It'll be written in a much more efficient method and will do a much more thorough job. Link to comment Share on other sites More sharing options...
Blue_Drache Posted January 13, 2005 Share Posted January 13, 2005 If this is your intention, then I'd look for some free software that already does this. It'll be written in a much more efficient method and will do a much more thorough job.<{POST_SNAPBACK}>Stick in the mud.........Anyway, I think that writing this is a good idea for basic *HOME* security for the paranoid user...and it is a lesson on how to make files of X size with random data in it. I will concede that Valik does have a valid point. Norton has a good file wiper, as well as blank space wiping that only took about 3 hours to do my 40GB drive with government settings (3 passes: write all 1's, write all 0's, write random binary pattern.)Spybot S&D also has a "file shredder" that performs a secure removal of a file, but you have to use the Spybot GUI to access it. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now