dreamvb
asked on
Please Help WriteFile API
Hi I can someone give me some examples and reading and writeing files useing the Win API at the moment I have just been useing the normal vb way Open file for binary and so On.
Anyway Since I made a new program that can removes files form your system like a file wipeing tool I have run in to problums with the speed when dealing with big files anyway I hope someone can help. I have also included some of the code I am useing the so you will see what I mean when I say it goes solw. well I hope someone can help anyway I will be very helpfull.
Private Function WipeFiles(lzPath As String)
Dim Icount As Long
Dim TChar1 As String
Dim TChar2 As String
Dim T As Long
TFile = FreeFile
On Error Resume Next
x = Dir(lzPath, vbHidden)
Do While x <> ""
Open lzPath & x For Binary As #TFile
FLen = LOF(TFile)
For Icount = 0 To FLen
Randomize
TChar1 = Chr(Val(Int(160 * Rnd) + 1))
TChar2 = Chr(Val(Int(60 * Rnd) + 2))
T = Seek(TFile)
Put #TFile, TFile, TChar1
Put #TFile, T, TChar2
Next
Close #TFile
Kill lzPath & x
x = Dir
Loop
TChar1 = "": TChar2 = "": FLen = 0: Icount = 0: T = 0
End Function
Also please let me know if there is some thing wrong with the code I useing. or why it might be going slow
Anyway Since I made a new program that can removes files form your system like a file wipeing tool I have run in to problums with the speed when dealing with big files anyway I hope someone can help. I have also included some of the code I am useing the so you will see what I mean when I say it goes solw. well I hope someone can help anyway I will be very helpfull.
Private Function WipeFiles(lzPath As String)
Dim Icount As Long
Dim TChar1 As String
Dim TChar2 As String
Dim T As Long
TFile = FreeFile
On Error Resume Next
x = Dir(lzPath, vbHidden)
Do While x <> ""
Open lzPath & x For Binary As #TFile
FLen = LOF(TFile)
For Icount = 0 To FLen
Randomize
TChar1 = Chr(Val(Int(160 * Rnd) + 1))
TChar2 = Chr(Val(Int(60 * Rnd) + 2))
T = Seek(TFile)
Put #TFile, TFile, TChar1
Put #TFile, T, TChar2
Next
Close #TFile
Kill lzPath & x
x = Dir
Loop
TChar1 = "": TChar2 = "": FLen = 0: Icount = 0: T = 0
End Function
Also please let me know if there is some thing wrong with the code I useing. or why it might be going slow
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>Use bigger blocks and a predefined char to write with as in this example and it should be faster.
As long as you use bigger blocks it doesn't matter if you use a predefined character or not. Randomizing the data in the block is not the slow part.
As long as you use bigger blocks it doesn't matter if you use a predefined character or not. Randomizing the data in the block is not the slow part.
ASKER
Thanks this now seems to work a lot better now
Thanks again and also thanks the rest of you.
Thanks again and also thanks the rest of you.
PaulHews,
I haven't timed it at all, but shouldn't throwing two more function calls in the middle of the loop slow it down more? I can understand it might not be much, but wouldn't it be something a bit slower? Thanks for the info if you respond.
Shannon
I haven't timed it at all, but shouldn't throwing two more function calls in the middle of the loop slow it down more? I can understand it might not be much, but wouldn't it be something a bit slower? Thanks for the info if you respond.
Shannon
Open lzPath & x For Output #TFile