Topic: zwObject.RemoveFile()?

Hi!

What's the best way to remove a certain file from multiple zip files (1000+) without having to recreate them manually each time?

A command like "zwObject.RemoveFile(filename)" would be quite helpful here.

Grisu

Re: zwObject.RemoveFile()?

greetings Grisu i hope all is well smile  unfortunately the base library does not provide a delete file functionality.  the best i can do is create a new temp zip file and extract/rezip all the files not to be deleted into it.  it would be a convenience function but depending on the size of the zip it could take a while.  i could do the work in memory but again, depending on the machine's memory and the size of the zip i could fill that quick.  maybe make it optional?  would something like that work for you or were you working to avoid the recreation?

Re: zwObject.RemoveFile()?

I was hoping to avoid the recreation of a zip. But one can't have everything.

In the meantime I coded a basic function. The only little issue is that the tempory files aren't deleted from the HDD. Probably because there are still in use.

It might be best to do this stuff all in memory. With modern PCs this shouldn't be a problem (when you only store one file at a time). The process should be a lot faster than the HDD method.

Function Delete_File_from_Zip(InFile:String, OutFile:String, DelFile:String)

    Local zwObject:ZipWriter = New ZipWriter
    Local zrObject:ZipReader = New ZipReader
 
    If ( zrObject.OpenZip( InFile ) ) Then

    If ( zwObject.OpenZip( OutFile, False) ) Then
    
        Local ZipFileCount: Int = zrObject.getFileCount()
          
              Print ""
        Print "Working! '"+OutFile+"' - filecount: "+ZipFileCount
              Print ""
         
        For Local i:Int=0 To ZipFileCount-1
        
        Local FileName:String=zrObject.getFileInfo(i).simpleFileName
        
        If FileName <> DelFile Then
             
             zrObject.ExtractFileToDisk( FileName, FileName )
                zwObject.AddFile(FileName)
        
              DeleteFile( FileName )        
         '        Print FileName + " copied..."
        'Else
         '        Print FileName + " skipped..." 
        EndIf 

        Next 
        zwObject.CloseZip()
    EndIf

        zrObject.CloseZip()
    End If
    
End Function

If I'm the only user that does such file manipulations, it's not worth the time and effort.

Re: zwObject.RemoveFile()?

thanks for the sample code!  i will take a stab at this tonight and see what i come up with.