Zip all files in directory windows

Zip and unzip files

Zipped (compressed) files take up less storage space and can be transferred to other computers more quickly than uncompressed files. In Windows, you work with zipped files and folders in the same way that you work with uncompressed files and folders. Combine several files into a single zipped folder to more easily share a group of files.

Locate the file or folder that you want to zip.

Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder.

A new zipped folder with the same name is created in the same location. To rename it, press and hold (or right-click) the folder, select Rename, and then type the new name.

Locate the zipped folder that you want to unzip (extract) files or folders from.

Do one of the following:

To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location.

To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.

To add files or folders to a zipped folder you created earlier, drag them to the zipped folder.

If you add encrypted files to a zipped folder, they’ll be unencrypted when they’re unzipped, which might result in unintentional disclosure of personal or sensitive information. For that reason, we recommend that you avoid zipping encrypted files.

Some types of files, like JPEG images, are already highly compressed. If you zip several JPEG pictures into a folder, the total size of the folder will be about the same as the original collection of pictures.

Extract all Zip’s in a directory (incl. subfolders) with a .bat file or dos command

I want to extract all .zip’s and .rars in a folder and its children

The structure is like this:

I tried already this, which did not work

I use Windows and have 7-Zip installed.

Additional Question: Would it be possible to save all the extracted files from the last children (a.rar, b.rar) in one and the same folder (main folder)?

6 Answers 6

The Script:

Explanation:

This performs a loop for each file returned by the command dir /b /s *.zip *.rar . The /s tells dir to recurse into subdirectories and /b prints in bare format.

The filename is stored in the %%I variable for use later. If you were typing this at the prompt, you would use %I instead.

This performs the extraction. The argument -o»%%

dpI» extracts the file into the same directory where the archive resides. Other options:

dpI» — Extracts into the directory where the archive resides.

dpnI» — Creates a new directory in the hierarchy named after the archive and extracts there (that is, AFolder\archive.zip extracts into AFolder\archive\ ).

nI» — Creates a new directory in the current directory named after the archive and extracts there (that is, AFolder\archive.zip extracts into .\archive\ ).

Omit the -o argument — Extracts into the current directory.

Create .zip folder from the command line — (Windows)

Is it possible to create a .zip file from a folder in the command line, I don’t want to use any third party executable.

I was thinking something like ‘send to compressed folder’ but I don’t know how to do it.

11 Answers 11

Windows 10 includes tar.exe :

If you have older Windows, you can still download it:

PowerShell

Directory

For both tools, you can use a file or directory for the input.

Читайте также:  Nginx ������ ��� linux

Imagine that you want to compress the same folder that you are on Command Prompt WITHOUT opening a powershell window:

I don’t think there is a command line for ZIP files built in to Windows (Other than compress in Server 2003 Resource Kit). You’d have to use a third party. Everybody loves 7zip!

I’ve combined this script from several different sources to suit my needs better. Copy and paste the script into a file with the extension «.vbs». The script was originally made for Windows XP, but it also works in Windows 7 x64 Ultimate — no guarantee’s if Windows will keep around the various Shell objects this uses.

Usage: in the run box or command line put-

Path to script, source folder, zip file to make (include .zip at the end).

It won’t copy empty folders so be careful.

Here is the vbs code —

It is possible to run PowerShell script from BAT. Bat file receive path to dir to be zipped and zip file name as parameters.

I will post something related to WSkids answer as sadly i cannot use the comment function.

Using the CopyHere() method in VBS introduces several issues. One of these issues is that the method returns immediately while the copy process starts in background whereas multiple CopyHere() calls will interfere each other and the ZIP won’t be created correctly. A wait loop is needed here to fix that. My wait loop is based on an answer to a similar issue posted here.

Here is an updated version which fixes the «Object required» error reported by pihentagy. It’s a timing issue as the newly created ZIP file is included in the Items collection when the script is executed on fast machines.

Unzip All Files In A Directory

I have a directory of ZIP files (created on a Windows machine). I can manually unzip them using unzip filename , but how can I unzip all the ZIP files in the current folder via the shell?

Using Ubuntu Linux Server.

16 Answers 16

This works in bash, according to this link:

Just put in some quotes to escape the wildcard:

The following bash script extracts all zip files in the current directory into new dirs with the filename of the zip file, i.e.:

The following files:

Will be extracted to:

Shell script:

unzip *.zip, or if they are in subfolders, then something like

Unzip all .zip files and store the content in a new folder with the same name and in the same folder as the .zip file:

This will extract all the zip files in current directory, what if I want the zip files (present in subfolders) to be extracted in the respective subfolders ?

This will unzip all the zip archives into new folders named with the filenames of the zip archives.

a.zip b.zip c.zip will be unzipped into a b c folders respectively.

In any POSIX shell, this will unzip into a different directory for each zip file:

aunpack -e *.zip , with atool installed. Has the advantage that it deals intelligently with errors, and always unpacks into subdirectories unless the zip contains only one file . Thus, there is no danger of polluting the current directory with masses of files, as there is with unzip on a zip with no directory structure.

If by ‘current directory’ you mean the directory in which the zip file is, then I would use this command:

excerpt from find’s man page

Like -exec, but the specified command is run from the subdirectory containing the matched file, which is not normally the directory in which you started find. This a much more secure method for invoking commands, as it avoids race conditions during resolution of the paths to the matched files. As with the -exec option, the ‘+’ form of -execdir will build a command line to process more than one matched file, but any given invocation of command will only list files that exist in the same subdirectory. If you use this option, you must ensure that your $PATH environment variable does not reference the current directory; otherwise, an attacker can run any commands they like by leaving an appropriately-named file in a directory in which you will run -execdir.

Zip all files in directory windows

a command line
multi function tool.

Читайте также:  Usb камера с микрофоном linux

free external tools,
zero install effort,
usb stick compliant:

How to get zip and unzip on the windows command line for quick creation and extraction of zip compressed files.

Download the free Windows executables: (for Linux, see below)

    to extract zip files on the command line, download unzip.exe here.

this file is a copy of the original Info-ZIP unzip.exe version 5.52, provided for free under the Info-ZIP license. Alternatively, you may download it via the original Info-ZIP website.

How to use unzip? Read the examples below.

to create zip files on the command line, download zip.exe here.

this file is a copy of the original Info-ZIP zip.exe version 2.32, provided for free under the Info-ZIP license. Alternatively, you may download it via the original Info-ZIP website.

How to use zip? Read the examples below.

  • to create or extract zip files more flexible, like
    • include or exclude sub folders or filenames
    • zip only files changed today, or in the last 3 days
    • with full UTF-8 unicode filename support

    download Swiss File Knife here. Then type sfk zip or sfk unzip and read the examples.

    this tool is created and maintained only by this website, www.stahlworks.com, and not associated with Info-ZIP. Swiss File Knife Base is Free Open Source, BSD licensed. (more)

    to extract .tar.gz and .tar.bz2 files under windows, download:

    gzip.exe 1.3.12 a copy from http://gnuwin32.sourceforge.net/
    bzip2.exe 1.0.5 a copy from http://www.bzip.org/
    tar.exe a copy from http://sourceforge.net/projects/unxutils/

    All binaries can be used instantly, requiring no further DLL’s.
    Some command examples:

    gzip -d foo.tar.gz uncompresses foo.tar.gz, replacing it by foo.tar
    bzip2 -d foo.tar.bz2 uncompresses foo.tar.bz2, replacing it by foo.tar
    tar tvf foo.tar lists the contents of foo.tar
    tar xvf foo.tar extracts the contents of foo.tar
    • Zip and Unzip for newer (lib6 based) distributions: unzip 5.51, zip 2.3
    • Zip and Unzip for older (lib5 based) distributions: unzip 5.50, zip 2.3

    These files are copies from the Info-Zip download locations listed above,
    provided under the Info-ZIP license.

  • The gzip, bzip2 and tar commands should be available on your linux already.
  • zzfind and sfk for newer (lib6 based) distributions: zzfind, sfk
  • zzfind and sfk for newer (lib5 based) distributions: zzfind, sfk

    These files are provided for free under the BSD license.

    Further zip tools of possible interest:

    Although not discussed here, it should be mentioned that the original Info-ZIP homepage provides further tools, e.g. for the creation of self-extracting zips, gzip and zipsplit, and of course zip/unzip binaries for many other operating systems.

    Example for searching through zip file contents:

    searches all .java files within eclipse.zip for lines with the words «public» AND «class».
    Note that zzfind can also search files in a zip within a zip (nested zips).

    How to list nested zip file contents (zips or jars within zips):

    For example, if you download the Eclipse SDK and type you get a listing of less than 2000 files, listing also .jar file names. But how can you also list what is inside the .jar files, without the need to extract everything first?

    Download Swiss File Knife Base, then type: This will produce a listing of all files, no matter how deeply nested — in total nearly 70000 lines that can be very long, for example:

    eclipse-SDK-3.3.2-win32.zip\\eclipse\plugins
    \org.eclipse.ant.core_3.1.200.v20070522.jar\\lib
    \antsupportlib.jar\\org\eclipse\ant
    \internal\core\ant\EclipseAntMain.class

    The above is the text of a single line (filename), split into 4 lines here for better reading.

    As you can see, there is a .class file in a .jar within another .jar within the .zip.

    Limitations: SFK may not be able to process very large zip files, zip files with an unusual compression method, or 64 bit zip files. Type sfk help xe to list all limitations.

    How to list the contents of all .zip files in all subdirectories:

    In the example above, we listed the content of a single zip file. But sfk can also list the contents of all .zip, .jar, .ear, .war and .aar files in a directory tree. type: and get the most comprehensive listing of all files, all .zip (.jar etc) file contents
    and even zip contents embedded within other zips.

    Flexible file selection for zipping, using sfk:

    If you don’t want to zip all files of a directory tree, but for example

    • files that changed today, or since a date
    • files with a specific file extension
    • all files except those in subdirectories \save\ and \tmp\
    • files that are different compared to another directory

    then you have to prepare a file list with the swiss file knife, and send this to the zip tool through zip’s option -@ (read file list from standard input).

    example: zipping files changed today

    four files were changed today, so only those are packed into update.zip.

    example: including/excluding by filename

    only files with extension .txt are collected from the docs directory, excluding files
    • which are located in any subdirectory named «tmp»
    • having «-save.» in their name

    the example uses sfk for windows syntax. linux users have to type «:» instead of «!».

    example: comparing directories

    we have two directory trees, «docs» and «docs-old». the latter one is a copy of docs, made some days ago. meanwhile, there have been changes in «docs». but what changes?

    this command only lists what has changed so far:
    • some files have been added.
    • some files have differences, i.e. have been edited meanwhile.

    so let’s collect all these differences into a .zip. notice that zip would be irritated by the [add] and [dif] prefixes in each line, therefore we have to add sfk option -pure:

    now let’s send this to zip:

    NTFS and ZIP — execution prevention problem:

    i experienced one small problem when using the command-line (un)zip together with NTFS file systems; in short terms, after unzipping «.msi» files, I was unable to install software from these files. windows complained that access to the files was not possible or denied (due to some «execution prevention» mechanism introducted with XP SP2). this was probably because i zipped those files from a FAT partition (maybe even with an older zip tool) and then unzipped them on NTFS. the solution was to copy the files to a partition with FAT(32) file system, e.g. an USB stick, and then to run the installer from there.

    NTFS and ZIP — filetime jumps:

    another issue concerns filetimes, especially when zipping/unzipping accross FAT and NTFS partitions. in short terms, if you zip files from a FAT partition, then unpack this .zip on an NTFS partition, you always have to expect that the filetimes may be changed globally by a few hours. This is not at all a bug in the zip tool — it’s due to the way that NTFS manages filetimes internally. in case you’re irritated by this, try the following: 1) remember the filetimes in some directory on an NTFS partition. 2) change the date of your system from summer to winter time, or vice versa 3) have a look again at the filetimes and be shocked: all file times have jumped by one hour! so this is not a zip-specific problem, but it may show up when you compare times listed in a .zip file with those of the files actually created.

    Читайте также:  Когда надо менять windows
  • Оцените статью