All good day!
How can I change the program so that it checks the file extensions in a loop and, if the extension of these files is zip, then unzips it? Thus, no matter how many nested archives there are, the program unpacked all of them. Thanks.
UnzipUnrar.zip (31.4 KB)
All good day!
To achieve this you should put your unzip logic into a workflow and invoke this workflow recursively, i.e.
1/ invoke the WF with ZIP file as argument
2/ inside the WF unzip into a temp folder
3/ step through all ZIP files in temp folder and for each ZIP repeat step 1/
Some discussion about recursion here
Found a sample that unpacks archive and moves files. How do I make it create a temporary folder and unpack all zipped files?
UnzipFilesAndGetFiles (2).xaml (8.8 KB)
This sample is fine start point.
You just need to swap the logic to allow recursive calling of the WF:
1/ first unzip ZIP file into a folder(1) (best would be folder name = ZIP file name)
2/ for each ZIP file in folder(1) invoke same workflow
It could look like this
I do not attach complete solution intentionally to support your learning
In invoke, set file name = folder name? The file name is obtained through Path.GetFileName (“the path where the files are in the archive”). In Create Folder name, we create a variable of the string type, in order to then create a folder name based on it. Right?
1/ You should pass ZIP name as argument to the WF (full name including path).
2/ From ZIP name you could make the folder name (ZIP name without extention) and create the folder
3/ Use ZIP name and folder name as arguments for ExtractToDirectory method
- So? (see screenshot)
- We get file names through a for each loop? How do I get just the filename? Truncate the file path (replace method) and leave only the name?
1/ No. ExtractToDirectory method require at least two parameters. See the documentation above.
2/ Path class implements many methods for folder/file name manipulation.
- sourceArchiveFileName and destinationDirectoryName?
The first parameter is where we get the files in the archive from, the second parameter is where we create the folder, right? Thanks.
Now to the second parameter you need to add an expression to extract the file name?
1/ Pls read the documentation CAREFULLY.
The path to the archive that is to be extracted.
The path to the directory in which to place the extracted files
2/ I believe I gave you enough hints, the rest you could find in Google.