hallo ng,
first of all, for the zipping progress i use the ziplib from
http://www.icsharpcode.net/OpenSourc...b/Default.aspx
now to my problem.
im trying to build a little application for zipping our webservers logfiles.
after zipping all files, i've tried to delete all files, but i couldnt. i
got an error message that i cannot delete a file, because it is still in
use. Here my two functions for that:
Function ZipAll()
Dim datei As FileInfo
For Each datei In retFiles
Dim zipPfad As String =
datei.FullName.ToString.Replace(datei.Extension.ToString, ".zip")
Zip(datei.FullName.ToString, zipPfad)
Next
End Function
Function Zip(ByVal fileIn As String, ByVal fileOut As String) As Boolean
Dim boReturn As Boolean
Try
Dim strFileName As String = fileIn
Dim s As ZipOutputStream = New
ZipOutputStream(File.Create(fileOut))
s.SetLevel(5)
Dim fs As FileStream = File.OpenRead(strFileName)
Dim buffer() As Byte = New Byte(fs.Length) {}
fs.Read(buffer, 0, fs.Length)
Dim entry As ZipEntry = New
ZipEntry(Path.GetFileName(strFileName))
s.PutNextEntry(entry)
s.Write(buffer, 0, buffer.Length)
s.Finish()
s.Close()
boReturn = True
Catch
boReturn = False
End Try
Return boReturn
End Function
retFiles is an arraylist with strings pointing to our logfiles.
i have a button for zipping, and one for deleting:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Button2.Enabled = False
Button3.Enabled = False
ZipAll()
Button2.Enabled = False
Button3.Enabled = True
End Sub
This is the click event for the zpping button. this is my little try to
enable the button when the zipall() has finished. but this didnt worked. the
delete button gets enabled, but my app crashes when pressed, because it
tries to delete files which are currently in use.
is there any way to determine if the zip function has really finished, or
does anybody got an idea for a workaround?
thx in advance
regards benjamin