PowerShell script not zipping correct files

Pass the files as full paths to the Zip function, using their .FullName property (PSv3+ syntax): Zip C:\Users\Admin\Desktop\TEST.zip $Files.FullName The problem is that, in Windows PowerShell, the [System.IO.FileInfo] instances returned by Get-ChildItem situationally[1] stringify to their file names only, which is what happened in your case, so your Zip function then interpreted the $toBeZipped values … Read more

Download multiple files as a zip-file using php

You can use the ZipArchive class to create a ZIP file and stream it to the client. Something like: $files = array(‘readme.txt’, ‘test.html’, ‘image.gif’); $zipname=”file.zip”; $zip = new ZipArchive; $zip->open($zipname, ZipArchive::CREATE); foreach ($files as $file) { $zip->addFile($file); } $zip->close(); and to stream it: header(‘Content-Type: application/zip’); header(‘Content-disposition: attachment; filename=”.$zipname); header(“Content-Length: ‘ . filesize($zipname)); readfile($zipname); The second … Read more

How to [recursively] Zip a directory in PHP? [duplicate]

Here is a simple function that can compress any file or directory recursively, only needs the zip extension to be loaded. function Zip($source, $destination) { if (!extension_loaded(‘zip’) || !file_exists($source)) { return false; } $zip = new ZipArchive(); if (!$zip->open($destination, ZIPARCHIVE::CREATE)) { return false; } $source = str_replace(‘\\’, “https://stackoverflow.com/”, realpath($source)); if (is_dir($source) === true) { $files … Read more

How to zip a whole folder using PHP

Code updated 2015/04/22. Zip a whole folder: // Get real path for our folder $rootPath = realpath(‘folder-to-zip’); // Initialize archive object $zip = new ZipArchive(); $zip->open(‘file.zip’, ZipArchive::CREATE | ZipArchive::OVERWRITE); // Create recursive directory iterator /** @var SplFileInfo[] $files */ $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { // … Read more

Is there a zip-like function that pads to longest length?

In Python 3 you can use itertools.zip_longest >>> list(itertools.zip_longest(a, b, c)) [(‘a1’, ‘b1’, ‘c1’), (None, ‘b2’, ‘c2’), (None, ‘b3’, None)] You can pad with a different value than None by using the fillvalue parameter: >>> list(itertools.zip_longest(a, b, c, fillvalue=”foo”)) [(‘a1’, ‘b1’, ‘c1’), (‘foo’, ‘b2’, ‘c2’), (‘foo’, ‘b3’, ‘foo’)] With Python 2 you can either use … Read more

How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools?

And here are the answer(s): 1. Using “pure” batch script to zip/unzip file. It’s possible thanks to Frank Westlake’s ZIP.CMD and UNZIP.CMD(needs admin permissions and requires FSUTIL and CERTUTIL) .For Win2003 and WinXP it will require 2003 Admin Tool Pack which will install CERTUTIL. Be careful as ZIP.CMD syntax is backward : ZIP.CMD destination.zip source.file … Read more

What characters are forbidden in Windows and Linux directory names?

Let’s keep it simple and answer the question, first. The forbidden printable ASCII characters are: Linux/Unix: / (forward slash) Windows: < (less than) > (greater than) : (colon – sometimes works, but is actually NTFS Alternate Data Streams) ” (double quote) / (forward slash) \ (backslash) | (vertical bar or pipe) ? (question mark) * … Read more

What can you use instead of zip?

It’s not clear why you’re using your own zip() instead of Python’s zip(), nor why you believe you need zip() at all. You can get this program to work by simplifying the code: fun_string = “””In ___0___, crazy ___1___ with ___2___, ate a meal called ___3___ on a grill””” horror_string = “””In ___0___ owned by … Read more