Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Question for moving a complete archive a notch

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

    Hi,

     I’m completly new to Xceed ZIP for .Net and I’ve been given the task of working with a zip file that’s produced by one of our software.

    The question is this situation: I have a rather large archive that has a 6-7 levels directory tree. To get this archive to operate the way we want, it’s necessary to create a new TOP folder (name it as we like) and move the structure into it, in the same zip.

    There are some MoveTo methods in the documentation and I’m working my way through them but I would appreciate all the help I can get.

    Can someone post a sample of what to do ?

     Thanks !

    Yves

    Imported from legacy forums. Posted by Yves (had 1414 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Yves,

    To achieve that you could follow the following steps:

    1. Create the new TOP folder.

    2. Create a new ZipArchive inside that folder.

    3. Get a reference to your ZipArchive.

    4. Move the content of your archive to the newly created ZipArchive.

    A simple code snippet which implements that could be:

        
                DiskFolder theSourceFoler = new DiskFolder(folderPath + “Work Folder”);
                DiskFolder theDestinationFolder = new DiskFolder(folderPath + “DestinationWorkFolder”);
                ZipArchive theDestinationZip = new ZipArchive(new DiskFile(folderPath + theDestinationFolder.Name + @”\CopyFolder.zip”));
                theSourceFoler.MoveTo(theDestinationZip, true);
                if (!theDestinationFolder.Exists)
                    theDestinationFolder.Create();

    Hope that helps.

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 368 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi and thank you for the code snippet. It helps but it’s not completly what I intend to do:

    Let’s say we have a zip that has the following content:

    \RootFolder

       -file 1

       -file 2

       – directory \RootFolder\foo

             – file a

             – file b

    The intent is to either rename \RootFolder directly in the zip (the best thing) or create a root directory \NewRoot and moving whatever is under

    RootFolder to \NewRoot and then delete \RootFolder. In the end we would have

    \NewRoot

       -file 1

       -file 2

       – directory \RootFolder\foo

             – file a

             – file b

    Then this: it needs to be done inside the archive, no way to write the thing to a temporay ZIP or another one and flushing the original.

    Can this be achieved ?

    Thanks !

    Yves

    Imported from legacy forums. Posted by Yves (had 328 views)

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi Yves,

    If I understood your question, you are looking to rename a Folder inside a ZipArchive file without modifying its contents. To achieve that,

    you could follow these steps:

    1. Obtain a reference to your ZipArchive file.

    2. Obtain a reference to the root directory inside that file, through the ZipArchive’s GetFolder method.

    3. Assign the desired name to the resulted folder.

    A simple code snippet which implements that could be:

                ZipArchive theHostZipArchive = new ZipArchive(new DiskFile(“The Path of your ZipArchive file”);
                if (theHostZipArchive.Exists)
                {
                    Console.WriteLine(“zip exist”);
                }
                ZippedFolder theTargetFolder = (ZippedFolder) theHostZipArchive.GetFolder(“The Root Folder inside your ZipArchive file”);
                theTargetFolder.Name = “The Name you would like to apply”;
                Console.WriteLine(“Renaming Done!”);

    Imported from legacy forums. Posted by Fawzi [Xceed] (had 1208 views)

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