zipfile

URI to file in Zip incorrect if path contains spaces

给你一囗甜甜゛ 提交于 2019-12-24 00:40:01
问题 I want to get the URIs to the entries of a zip file in order to keep references to it's contents without having to keep the zip file open. Therefore I open the zip file using the zip filesystem and export the Path of the entries as URI. Path zipfile = ... URI uriOfFileInZip; try(FileSystem fs = FileSystems.newFileSystem(zipfile, null)){ Path fileInZip = fs.getPath("fileInZip.txt"); uriOfFileInZip = fileInZip.toUri(); } Now I want to read the file again, so I try to open a stream to the file.

Python zipfile module - zipfile.write() file with turkish chars in filename

≡放荡痞女 提交于 2019-12-24 00:39:19
问题 On my system there are many Word documents and I want to zip them using the Python module zipfile . I have found this solution to my problem, but on my system there are files which contain German umlauts and Turkish characters in their filename. I have adapted the method from the solution like this, so it can process German umlauts in the filenames: def zipdir(path, ziph): for root, dirs, files in os.walk(path): for file in files: current_file = os.path.join(root, file) print "Adding to

zip main folder with sub folder inside

喜夏-厌秋 提交于 2019-12-23 10:11:25
问题 I have a folder with some files and sub folder inside. How im going to read the directory and zip the main folder? Ex: maindirectory --- file 1 --- file 2 --- subdirectory 1 ------ file 3 ------ file 4 --- subdirectory 2 ------ file 5 ------ file 6 I'm using this script: function Zip($source, $destination, $include_dir = false) { if (!extension_loaded('zip') || !file_exists($source)) { return false; } if (file_exists($destination)) { unlink ($destination); } $zip = new ZipArchive(); if (!$zip

How can i list only the folders in zip archive in Python?

故事扮演 提交于 2019-12-23 08:34:51
问题 How can i list only the folders from a zip archive? This will list every folfder and file from the archive: import zipfile file = zipfile.ZipFile("samples/sample.zip", "r") for name in file.namelist(): print name Thanks. 回答1: One way might be to do: >>> [x for x in file.namelist() if x.endswith('/')] <<< ['folder/', 'folder2/'] 回答2: I don't think the previous answers are cross-platform compatible since they're assuming the pathsep is / as noted in some of the comments. Also they ignore

How can i list only the folders in zip archive in Python?

ぐ巨炮叔叔 提交于 2019-12-23 08:34:47
问题 How can i list only the folders from a zip archive? This will list every folfder and file from the archive: import zipfile file = zipfile.ZipFile("samples/sample.zip", "r") for name in file.namelist(): print name Thanks. 回答1: One way might be to do: >>> [x for x in file.namelist() if x.endswith('/')] <<< ['folder/', 'folder2/'] 回答2: I don't think the previous answers are cross-platform compatible since they're assuming the pathsep is / as noted in some of the comments. Also they ignore

Zipping files in Django view and serving them

会有一股神秘感。 提交于 2019-12-23 05:11:41
问题 First of all I want to say that I know its bad to serve files from django but my situation can only be handled by django so I chose it to serve zipped files.In my models.py I have a model class Documents(models.Model): filename = models.CharField(max_length=100) document = models.FileField(upload_to='docs') allowedGroup = models.ManyToManyField(Group) So when a normal user log-in it will be displayed the Documents which he has permission according to his/her group.I want user to be able to

Accessing files inside a .zip archive without extracting them

有些话、适合烂在心里 提交于 2019-12-23 02:43:10
问题 I am attempting to read a NIFTI file inside a .zip without having to extract the directory to the root directory. More specifically, I am working with the ADNI database and the files are stored by subjectID in individual .zip files. Inside the .zip file there is all the data pertaining to that subject, I would like to extract the NIFTI file (.nii.gz) from within the .zip without extracting the files. Currently I have the following code snippet def openNIFTI(filename): return nib.load(filename

How to compress a folder to make docx file in android?

China☆狼群 提交于 2019-12-23 01:24:09
问题 I'm trying to make an Android application that can open a docx file to read, edit and save it. My idea is to extract all the xml file within the archive to a temp folder. In this folder we can edit the content of the docx in /word/document.xml . The problem is when I compress this temp folder to make a new docx file and replace the old file, inside the new docx archive the path is like /mnt/sdcard/temp/"all files xml go here" while the xml files should be in the first level. Can anybody help

Create password protected zip file Python [duplicate]

拟墨画扇 提交于 2019-12-22 08:34:21
问题 This question already has an answer here : Python - zipfile: how to set a password for a zipfile? [duplicate] (1 answer) Closed 2 years ago . I'm using following code to create password protected zip file, from a file uploaded by user, in my Python34 application using zipFile . But when I open the zip file from windows, it doesn't ask for the password. I will be using the same password to read zip files from python later on. What am I doing wrong? Here's my code: pwdZipFilePath =

Adding file to existing zipfile

孤街浪徒 提交于 2019-12-22 03:54:35
问题 I'm using python's zipfile module. Having a zip file located in a path of: /home/user/a/b/c/test.zip And having another file created under /home/user/a/b/c/1.txt I want to add this file to existing zip, I did: zip = zipfile.ZipFile('/home/user/a/b/c/test.zip','a') zip.write('/home/user/a/b/c/1.txt') zip.close()` And got all the subfolders appears in path when unzipping the file, how do I just enter the zip file without path's subfolders? I tried also : zip.write(os.path.basename('/home/user/a