ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to write a recursive function that will do recursive unzipping....
I will explain...
Suppose I have two zipped files and a folder that contains other folders, zipped files and other files...
I need to unzip each file and then check the type of the file...my end condition or terminating condition will be the non existence of a zipped file i.e. i will keep on unzipping till i no longer get a zipped file..this is on the assumption that there will be zipped files inside the zipped files.
Once i finish with the first file i need to go on to the next zipped file and then work on the folder that may contain other zipped files and folders...
Maybe i can implement using a tree data structure... i'm not very sure...
I have been unable to devise a way in which i can do this...
Hope somebody can help or give me some kind of an idea...
thanks
unzipThisFile() is the actual function that unzips the file to the dest_path.
check_path_for_zip_file() will read the names of all the zip files present in the folder and also change their extension to some other temp extension so that they are not checked by the next recursion.
reset_file_names() reset the extension of the files back to their original value.
I am not clear on why it needs to be recursive... Most of the time, it's quite possible (and better programming) to write such functions using some kind of while loop. Something like:
And of course, your getNextFile() or equivalent function would scan the current directory in alphabetical order or some such, go into subfolders, re-check after zip files are unzipped, or whatever. Recursion adds nothing to that except some possible problems with stack overflow
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.