help with recursion function
Hi,
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 |
Following code gives an brief outline of how you can do this using recursion.
my_unzip(File, dest_path) { char zip_file_names[10][100]; int num_files=0; unzipThisFile(File, dest_path); status = check_path_for_zip_file(dest_path, zip_file_names, num_files); if (status == ZIP_EXISTS) { for(i=0; i<num_files; i++) { my_unzip(File, dest_path) } } reset_file_names(dest_path); } 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. Yaser |
which language?
|
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:
Code:
while (zipFileExists) |
i'd be thinking that bash would be a more suitable language than c for unzipping a bunch of stuff.
Code:
for i in $1 |
All times are GMT -5. The time now is 01:10 PM. |