I am trying to add some zipping code to my program, however, i can’t seem to get the folder structure just right.
I want the folder to look like this:
Root (
-subfolder1
-subfolder2
individual file
individual file
individual file)
So, the indidivual files will be in the root folder of the zip and the folders that i add will become subfolders to the root. my code is below….
Using zip As New ZipFile()
For Each item As System.Xml.XmlNode In Source
If item.InnerText.Contains(".") Then
zip.AddFile(item.InnerText)
Else
zip.AddDirectory(item.InnerText, GetLastDirName(item.InnerText))
End If
Next
For Each item As System.Xml.XmlNode In Destin
Dim path As String = item.InnerText
zip.Save(path.Replace(".zip", "") & "_Archive_" & DateString & ".zip")
Next
End Using
however, the zip.addfile(item.innertext) line addes the individual files to the full path. So, if the file is C:\Pictures\image.jpg …it will appear as such in the zip file, with all the subfolders.
I have also tried things like zip.addfile(item.innertext, "individual files") to create a folder for just individual files…but meh, i want those files to be stored in the root.
Any suggestions?
If you look at the documentation for the method AddFile, there are two parameters you can pass in:
The Ionic documentation states that for that second parameter, the rules are as follows:
Source (http://dotnetzip.herobo.com/DNZHelp/html/202e1fb5-8891-888f-8e91-1340f7cd80c9.htm)
The means that in your code above, where you pass in only the first parameter (file name), you will use the full path off of the file you’re adding. Add the path you want to the AddFile method as your second parameter, and you’re good to go.