How to rename the zip entry...

Nov 13, 2010 at 2:59 AM

Hi,

A newbie question. I have generated my data in temp files but want to store them properly in the zip file.

How do I give the new name while adding the files to the zip file? 

For example: I have three tmp files.

lkijo343n.tmp

klsjdfklsjdlk.tmp

3kjljdlfsd.tmp

I want to store the above as

abc1.csv

abc2.csv

abc3.csv

Thanks.

Nov 13, 2010 at 4:41 AM

I think I just need to set the name after adding the entry...I will try that...

Coordinator
Nov 13, 2010 at 6:31 AM

yes, that should work, just fine.  Let me know if it does not work as you expect.

Nov 14, 2010 at 7:42 PM

Other point of view (and problem with renaming ;-) ) . I've tried to use rename script for existing zip file based on sequence in VB :

Using zip As ZipFile = ZipFile.Read( ZIPPath, System.Text.Encoding.GetEncoding(852))
...

For Each entry In Zip

   Index = Index +1

   entry.FileName = Index.ToString & Name

Next
 ...
Zip.Save()

End Using

But exception "InvalidOperationException: Collection was modified; enumeration operation may not execute." is resulted.

Could somebody prompt me?

Thanks,

 

 

Nov 22, 2010 at 7:05 PM

Instead of enumerating, loop:

 

For Index = 0 To Zip.Entries.Count

  Zip(Index).FileName = Index.ToString & Name

Next

Nov 27, 2010 at 9:26 AM

thanks, halcyon1234, you are absolutely right,

in this case enumerating is a stupid way and For works correctly (For Index = 0 To (Zip.Entries.Count - 1)  ;-)