How to Create a Zip File Without Entire Directory Structure

Create zip file and ignore directory structure

You can use -j.

-j
--junk-paths
Store just the name of a saved file (junk the path), and do not
store directory names. By default, zip will store the full path
(relative to the current directory).

How to create a zip file without entire directory structure

I don't believe zip has a way to exclude the top level directory. I think your best bet would be to do something like:
pushd /foo; zip -r out.zip ./bar; popd;

But this is exactly the sort of answer you said you didn't want.

zipping files in python without folder structure

From the documentation:

ZipFile.write(filename, arcname=None, compress_type=None,
compresslevel=None)

Write the file named filename to the archive, giving it the archive
name arcname (by default, this will be the same as filename, but
without a drive letter and with leading path separators removed).

So, just specify an explicit arcname:

with zp(os.path.join(self.savePath, self.selectedIndex + ".zip"), "w") as zip:
for file in filesToZip:
zip.write(self.folderPath + file, arcname=file)

zip file and avoid directory structure

The zipfile.write() method takes an optional arcname argument that specifies what the name of the file should be inside the zipfile

I think you need to do a modification for the destination, otherwise it will duplicate the directory. Use :arcname to avoid it. try like this:

import os
import zipfile

def zip(src, dst):
zf = zipfile.ZipFile("%s.zip" % (dst), "w", zipfile.ZIP_DEFLATED)
abs_src = os.path.abspath(src)
for dirname, subdirs, files in os.walk(src):
for filename in files:
absname = os.path.abspath(os.path.join(dirname, filename))
arcname = absname[len(abs_src) + 1:]
print 'zipping %s as %s' % (os.path.join(dirname, filename),
arcname)
zf.write(absname, arcname)
zf.close()

zip("src", "dst")

I want zip file without any directories in zip file.How can I do in c#

the ZipFile.AddItem method have another variant with two strings source file path and file path in archive.

You have to use :

        string filepath = @"C:\Users\Hüseyin\Desktop\AA\a.txt";
zip.AddItem(filePath, Path.GetFileName(filePath));

to put the a.txt file in the root directory of the zip file.

Create zip folder without top level, but keep subfolders

The way to do this is:

cd bundle
zip -r ../bundle.zip *
cd ..

https://unix.stackexchange.com/a/182036/101265

How to zip folder without full path

By default, zip will store the full path relative to the current directory. So you have to cd into public_html before running zip:

$output = 'cd /home/user/public_html; zip -rq my-zip.zip folder-one -x missthis/\*';
shell_exec($output);


Related Topics



Leave a reply



Submit