I think a more modern approach is to use scripts in programming languages, such as Python, so that it won't be limited to just one operating system. As far as I know, 7-zip can run on both Windows and MacOS/Linux. The steps to handle this issue are as follows:
Use the list of decompression file extensions supported by 7-zip to filter out all possible decompressible archive files in a certain directory (for example, tar, 7z, rar, etc.). Remember to use os.path.extsplit(path)[-1] to get the extensions of these files for filtering, because the following files may just coincidentally be named like "footar" and they are not archives; only those like "foo.tar" are.
Use the 7z t command to test these compressed archive files and filter out those that fail the test (because some files, although ending with these supported compressed archive suffixes, may be corrupted archives).
Use 7z x or 7z e to extract these valid compressed archive files. The specific command to use depends on the file directory format you expect to obtain.
Recursively execute the above steps, and end the recursion when no available compressed packages are found in the first step, so as to decompress the nested compressed package files within the compressed packages
This is just an implementation logic. I'm sorry, but I won't attach specific code because everyone's expected results are different, and there may be some additional customization requirements.