|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Zip clientI have a simple zip client and all work ok. But when it zips it creates every single folder that leads up to the folder i want to zip. I.e users - adamplowman - sites - rubberduckiee - xhina - files - pictures when all i want the zip folder to show is just whats in the pictures folder. [code] import zipfile, os def makeArchive(fileList, archive): """ 'fileList' is a list of file names - full path each name 'archive' is the file name for the archive with a full path """ try: paths = os.path.abspath('') a = zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED) for f in fileList: print "archiving file %s" % (f) a.write(f) a.close() return True except: return False def dirEntries(dir_name, subdir, *args): paths = os.path.abspath('') fileList = [] for file in os.listdir(paths+"/rubberduckiee/Xinha/plugins/ ExtendedFileManager/files/"+dir_name): dirfile = os.path.join(dir_name, file) if os.path.isfile(paths+"/rubberduckiee/Xinha/plugins/ ExtendedFileManager/files/"+dirfile): if not args: fileList.append(paths+"/rubberduckiee/Xinha/plugins/ ExtendedFileManager/files/"+dirfile) else: if os.path.splitext(dirfile)[1][1:] in args: fileList.append(paths+"/rubberduckiee/Xinha/ plugins/ExtendedFileManager/files/"+dirfile) # recursively access file names in subdirectories elif os.path.isdir(paths+"/rubberduckiee/Xinha/plugins/ ExtendedFileManager/files/"+dirfile) and subdir: print "Accessing directory:", dirfile fileList.extend(dirEntries(dirfile, subdir, *args)) return fileList if __name__ == '__main__': folder = "Pictures" zipname = 'test.zip' makeArchive(dirEntries(folder, True), zipname) [/code] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Zip client> I have a simple zip client and all work ok. But when it zips it > creates every single folder that leads up to the folder i want to zip. > I.e > > users - adamplowman - sites - rubberduckiee - xhina - files - > pictures > > when all i want the zip folder to show is just whats in the pictures > folder. > > [code] > import zipfile, os > > def makeArchive(fileList, archive): > """ > 'fileList' is a list of file names - full path each name > 'archive' is the file name for the archive with a full path > """ > try: > paths = os.path.abspath('') > a = zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED) > for f in fileList: > print "archiving file %s" % (f) > a.write(f) > a.close() > return True > except: return False > > def dirEntries(dir_name, subdir, *args): > > paths = os.path.abspath('') > fileList = [] > for file in os.listdir(paths+"/rubberduckiee/Xinha/plugins/ > ExtendedFileManager/files/"+dir_name): > dirfile = os.path.join(dir_name, file) > if os.path.isfile(paths+"/rubberduckiee/Xinha/plugins/ > ExtendedFileManager/files/"+dirfile): > if not args: > fileList.append(paths+"/rubberduckiee/Xinha/plugins/ > ExtendedFileManager/files/"+dirfile) > else: > if os.path.splitext(dirfile)[1][1:] in args: > fileList.append(paths+"/rubberduckiee/Xinha/ > plugins/ExtendedFileManager/files/"+dirfile) > # recursively access file names in subdirectories > elif os.path.isdir(paths+"/rubberduckiee/Xinha/plugins/ > ExtendedFileManager/files/"+dirfile) and subdir: > print "Accessing directory:", dirfile > fileList.extend(dirEntries(dirfile, subdir, *args)) > return fileList > > if __name__ == '__main__': > > folder = "Pictures" > zipname = 'test.zip' > makeArchive(dirEntries(folder, True), zipname) > > [/code] Since this question has nothing to do with tg I'd suggest asking for help on python-list@... the regular python mailing list. For subscription info please see http://mail.python.org/mailman/listinfo/python-list Also, I'd think reading the documentation of zip might help. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |