Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Zipping multiple folders with & without subfolders, incl relative paths

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20468 |

    I’m new to Xceed Zip for .Net.

    I’m looking for suggestions for the most efficient method for doing the following:
    1) There is a BaseFolder on a share.  eg \\Share1\MyDate\BaseFolder
    2) Within the BaseFolder are multiple folders,
     some of which I want to zip NOT including any subfolder   eg Folder1
     some of which I want to zip including SOME subfolders     eg Folder2\Sub1 and Folder2\Sub2, but not Folder2\Sub3
     some of which I want to zip including ALL subfolders      eg Folder3\Sub1…Sub4

    3) Each file in the final archive must include its path relative to the BaseFolder
            eg BaseFolder\Folder1\File1

    I have spent some time trying to create the code for this, but I feel like I’m trying to reinvent the wheel.
    I’ve looked at the sample code, but it includes only the simplest conditions.

    Any help will be greatly appreciated.

    Imported from legacy forums. Posted by Steve (had 2160 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Steve,

    In order to achieve this, you will need to use the CopyFilesTo method. The CopyTo method will take your BaseFolder and place it in a ZipArchive. You will not be able to filter the directory. The CopyTo folder will only be able to satisfy your third condition where you want it to include the current BaseFolder directory plus its children. As for the other conditions, you can do the following:

    1) some of which I want to zip NOT including any subfolder  eg Folder1
     –> source.CopyFilesTo(zEvents, “source.CopyFilesTo”, zip, false, true, “”);

    Must set the recursive property to false in your parameter list. Because you will be setting recursive to false, the CopyFilesTo will not copy the subdirectories and their files over to the ZipArchive.

    2) some of which I want to zip including SOME subfolders    eg Folder2\Sub1 and Folder2\Sub2, but not Folder2\Sub3
     –>
    source.CopyFilesTo(zEvents, “source.CopyFilesTo”, zip, true, true, new
    NotFilter(new NameFilter(“Test 1”, FilterScope.Recurse)));

    The only way to do this is to list the folder that you do NOT want to copy to your ZipArchive. In order to do this, you will need to provide a NotFilter as your filter so that the CopyFilesTo method will not copy the directories that you stated in your ZipArchive.

    3) some of which I want to zip including ALL subfolders      eg Folder3\Sub1…Sub4
     –> source.CopyFilesTo(zEvents, “source.CopyFilesTo”, zip, true, true, “”);

    You can do the following operation, or you can simply use the CopyTo method. We are simple setting the recursive property to true so that the CopyFilesTo method will copy everything and place it in your ZipArchive.

    Imported from legacy forums. Posted by Marc [Xceed] (had 263 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you Marc.  That was helpful.

    I still don’t understand, however, how to include in the final archive the relative path (relative to BaseFolder) for each file.  The directory structure looks something like this:

    \\Share1\MyData\BaseFolder\Folder1\SubFolder1

    When I use the following code, I need the relative path included for each file to be “BaseFolder\Folder1\SubFolder1”

    Dim source As New DiskFolder(“\\Share1\MyData\BaseFolder\Folder1\SubFolder1”)

    source.CopyFilesTo(zip, False, True, “*.txt”)

     

    Is there a way to accomplish this?

     

    Imported from legacy forums. Posted by Steve (had 305 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    This was answered via email support, but just in case others find this forum thread, here is the answer:

    You can do it this way:

       Dim source As New DiskFolder(“\\Share1\MyData\BaseFolder\Folder1\SubFolder1”)
       Dim dest As AbstractFolder

       ‘ Get a folder in the zip archive that has the name and structure we want
       ‘ Notice that the folders won’t exist in the archive yet. This is fine and even desirable for optimal performance. The component will create the folders as needed during copy operations.
       dest = zip.GetFolder( “BaseFolder\Folder1\SubFolder1” )

       ‘ Copy the source files to the destination folder
       ‘ This will create the folder structure in the zip archive as needed
       source.CopyFilesTo(dest, False, True, “*.txt”)

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 1140 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.