0

I have a folder and some files inside the folder. I need to zip the folder along with its content. For example: the folder name is "Help" adn it has around 20 files inside it. Now i need to make it as "Help.zip" which consist of 20 files. And need to delete the "Help" folder. Once Zipped only the zip folder should be available. Can some one help me by passing an example or a link. As i m very new to python.

Note: I have a very old version of Python. Its 2.2.1 :(

Deduplicator
  • 43,322
  • 6
  • 62
  • 109
pauler
  • 107
  • 2
  • 3
  • 9
  • Have you Googled first? http://stackoverflow.com/questions/296499/how-do-i-zip-the-contents-of-a-folder-using-python-version-2-5 – Blender May 09 '12 at 05:39
  • I did. I have got the below code: – pauler May 09 '12 at 08:32
  • But the below code does the zipping of the folder(krail) i gave, but the folder(krail) has 1 more folder(xyz) inside it, it does not zip the folder(xyz) but nly files of folder(krail) are been zipped: the code is "def zipfolder" – pauler May 09 '12 at 08:38
  • def zipfolder(foldername, target_dir, status): if status == 0: zipobj = zipfile.ZipFile(foldername + '.zip','w',zipfile.ZIP_DEFLATED) else: zipobj = zipfile.ZipFile(foldername + '.zip','a',zipfile.ZIP_DEFLATED) rootlen = len(target_dir) + 1 print "rootlen", rootlen , "\n" list = os.listdir(target_dir) for dirs in list: name = os.path.join(target_dir,dirs) print "Files in folders are :",os.path.basename(name) if os.path.isfile(name): zipobj.write(name, name[rootlen:]) elif os.path.isdir(name): print "Entering next folder" zipfolder(foldername, name, 1) – pauler May 09 '12 at 08:39
  • Please install another version of python such as python2.5 and copy the zipfile module to there. You may find it under zipfile.__file__ when importing it with the later python version. – User May 09 '12 at 08:59
  • Thanks fr the comment. Here i got a zip function which runs in python2.2.1 – pauler May 10 '12 at 02:45
  • @User: zipfile has been in there since version 1.6 no need to upgrade for that. – Anthon Apr 04 '13 at 14:49

0 Answers0