Recursive Directory Unzip
Posted: 24 Jun 2021 14:16
I'm creating my first script and have made good progress until I reached the recursion where "Try Script" can be less helpful.
This is a recursive script, so the idea is that it must be a function that calls itself. Eventually it will do two things (a) recurse all folders/subfolders, then (b) enumerate and unzip any .ZIP/.RAR files that it finds in those folders.
Here's the current code:
All of the code seems to work; however, the recursion doesn't seem to be working.
Any ideas what I might be doing wrong? Or, f there are similar examples that you can link, that might help me find the problem. Unfortunately I haven't been able to find any similar examples. I have found many topics on recursion; none of them that actually appeared to be true recursion that would work for my purposes.
Thank you in advance!
This is a recursive script, so the idea is that it must be a function that calls itself. Eventually it will do two things (a) recurse all folders/subfolders, then (b) enumerate and unzip any .ZIP/.RAR files that it finds in those folders.
Here's the current code:
Code: Select all
//Begin Script; Enumerate paths that have been selected in the XYplorer UI
foreach($dir, <get selecteditemspathnames |>, "|" ) {
function folderList($dir);
}
//Function to parse folders, the call itself to parse subfolders.
//If there are .ZIP files, in addition to folders, those will be processed
function folderList($dir) {
$folderList = listfolder($dir, "*", 2, "|");
foreach($folder, $folderList, "|") {
//for each folder, enumerate that by calling this same function
function folderList($folder);
}
$fileList = listfolder($dir, "*.zip;*.rar;*.7z", 1, "|");
foreach($file, $filelist, "|") {
echo $file;
//unzip goes here, once working.
}
}Any ideas what I might be doing wrong? Or, f there are similar examples that you can link, that might help me find the problem. Unfortunately I haven't been able to find any similar examples. I have found many topics on recursion; none of them that actually appeared to be true recursion that would work for my purposes.
Thank you in advance!