Skip to content

Unzips zip files to generically named new folders (a Windows PowerShell script).

License

Notifications You must be signed in to change notification settings

auberginehill/unzip-silently

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Unzip-Silently.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description: Unzip-Silently uses the Shell.Application to unzip files that are defined with the -FilePath parameter. By default the -FilePath parameter accepts plain filenames (then the current directory gets searched for the inputted filename) or 'FullPath' filenames, which include the path to the file as well (such as C:\Windows\archive.zip). If the -Include parameter is used, also paths to a folder may be entered as -Filepath parameter values, and then all the zip files inside the first directory level of the specified folder (as indicated by the common command 'dir' for example) are added to the list of files to be processed. Furthermore, if the -Recurse parameter is used in adjunction with the -Include parameter in the command launching Unzip-Silently, the search for zip files under the directory, which is defined with the -FilePath parameter, is done recursively (i.e. the zip files are searched from every subfolder level).

The naming principle of the new folders follows the original names of the zipped files. The contents of the zip files are extracted to new folders, which are created by default to the same folder, where each zip file is located. The default output destination folder, under which the new folder(s) is/are created, may be changed with the -Output parameter. When creating new folders Unzip-Silently tries to preserve pre-existing content rather than overwrite any existing folders (or files eventually), so if a folder seems to already exist, a similarly named folder with a (possibly higher) number is created instead.

After the contents of the zip files has been extracted, the MD5 and SHA256 hash values of the zip files (in machines that have PowerShell version 4 or later installed with the inbuilt Get-FileHash cmdlet and in machines that are running PowerShell version 2 or 3 by calling a Check-FileHash function, which is based on Lee Holmes' Get-FileHash script in "Windows PowerShell Cookbook (O'Reilly)") along with other performance related info is displayed in console.

To delete the original zip file(s), the parameter -Purge may be added to the launching command. Please note that if any of the individual parameter values include space characters, the individual value should be enclosed in quotation marks (single or double) so that PowerShell can interpret the command correctly.
Homepage: https://github.com/auberginehill/unzip-silently
Short URL: http://tinyurl.com/zkg7s9l
Version: 1.0
Sources:
Emojis: Emoji Table
Lee Holmes: Windows PowerShell Cookbook (O'Reilly): Get-FileHash script
Downloads: For instance Unzip-Silently.ps1. Or everything as a .zip-file.

Screenshot

        screenshot

Parameters

πŸ“
  • Parameter -FilePath

    with aliases -FilenameWithPathName, -FullPath, -Source, -File, -ZipFile and -Zip. The -FilePath parameter determines, which zip file(s) (or folders that might contain zip file(s)) is/are selected for content extraction, and in essence define the objects for Unzip-Silently.

    By default the -FilePath parameter accepts plain filenames (then the current directory gets searched for the inputted filename) or 'FullPath' filenames, which include the path to the file as well (such as C:\Windows\archive.zip). If the -Include parameter is used, also paths to a folder may be entered as -FilePath parameter values – then all the zip files inside the first directory level of the specified folder (as indicated by the common command 'dir' for example) are added to the list of files to be processed. Furthermore, if the -Recurse parameter is used in adjunction with the -Include parameter in the command launching Unzip-Silently, the search for zip files under the directory, which is defined with the -FilePath parameter, is done recursively (i.e. the zip files are searched from every subfolder level).

    To enter multiple zip files (or folders that might contain zip file(s) for content extraction, please separate each individual entity with a comma. If the filename or the directory name includes space characters, please enclose the whole string (the individual entity in question) in quotation marks (single or double). It's not mandatory to write -FilePath in the unzip command to invoke the -FilePath parameter, as is shown in the Examples below, since Unzip-Silently is trying to decipher the inputted queries as good as it is machinely possible within a 50 KB size limit. The -FilePath parameter also takes an array of strings and objects could be piped to this parameter, too. If no value for the -FilePath parameter is defined in the command launching Unzip-Silently, the user will be prompted to enter a -FilePath value.

  • Parameter -Output

    with an alias -OutputFolder. Specifies the folder, under which the new folder(s) with the extracted zip file content is/are to be saved. For best results the -Output parameter value should be a valid file system path, which points to an existing directory (for example C:\Windows\). When creating new folders (under the defined -Output folder) Unzip-Silently tries to preserve pre-existing content rather than overwrite any folders (or files eventually), so if a folder seems to already exist, a similarly named folder with a (possibly higher) number is created instead inside the directory indicated by the -Output parameter. If no value for the -Output parameter is defined in the command launching Unzip-Silently, the zip files are unzipped to new folders, which are created to the same folder, where each zip file is located.

  • Parameter -Include

    with aliases -IncludeZipFilesInTheFolderDefinedWithTheFilepathParameter, -IncludesFolders, -Folders and -Folder. If the -Include parameter is added to the command launching Unzip-Silently, also paths to a folder may be succesfully entered as -FilePath parameter values: all the zip files inside the first directory level of the specified folder (as indicated by the common command 'dir' for example) are added to the list of files to be processed.

  • Parameter -Recurse

    If the -Recurse parameter is used in adjunction with the -Include parameter in the command launching Unzip-Silently, the search for zip files under the directory, which is defined with the -FilePath parameter is done recursively (i.e. the zip files are searched from every subfolder level).

  • Parameter -Purge

    with aliases -DeleteZip, -DeleteOriginal and -Delete. If the -Purge parameter is added to the command launching Unzip-Silently, the original zip file(s) is/are deleted after the contents of the zip file(s) has been extracted.

Outputs

➑️
  • Unzips zip files.

  • If the -Purge parameter is added to the command launching Unzip-Silently, the original zip file(s) will be deleted.
  • For each zip file content extraction procedure a progress bar is shown in a separate window, which closes after the extraction has been done. Another progress bar is also shown in console, if multiple zip files are being processed.

Notes

⚠️
  • Please note that all the parameters can be used in one unzip command and that each of the parameters can be "tab completed" before typing them fully (by pressing the [tab] key).

Examples

πŸ“– To open this code in Windows PowerShell, for instance:

  1. ./Unzip-Silently -FilePath archive.zip
    Run the script. Please notice to insert ./ or .\ before the script name. The current directory gets searched for the inputted filename ("archive.zip") and the contents of the archive.zip would be extracted to the current directory (where the "archive.zip" is located) under a newly created folder called "archive".

    During the unzip procedure Unzip-Silently tries to preserve pre-existing content rather than overwrite any existing folders (or files eventually), so if a folder called "archive" seems to already exist, a similarly named folder with a number is created instead (inside which the contents of "archive.zip" is extracted). Please note, that the word -FilePath may be omitted in this example and that the -Filepath value ("archive.zip") doesn't need to be enveloped in quotation marks, since it doesn't contain any space characters.
  2. help ./Unzip-Silently -Full
    Display the help file.
  3. ./Unzip-Silently -FilePath "C:\Windows\explorer.zip" -Output "C:\Scripts"
    Run the script and extract the contents of "C:\Windows\explorer.zip" to "C:\Scripts\explorer". During the unzip procedure Unzip-Silently tries to preserve pre-existing content rather than overwrite any existing folders (or files eventually), so if a folder called "C:\Scripts\explorer" seems to already exist, a similarly named folder with a number is created instead (inside which the contents of "explorer.zip" is extracted). Please note, that the word -FilePath may be omitted in this example and that the paths don't need to be enveloped in quotation marks, because

    /Unzip-Silently C:\Windows\explorer.zip -Output C:\Scripts

    will result in the same outcome.
  4. ./Unzip-Silently C:\Users\Dropbox\, C:\dc01 -Include -Output C:\Scripts -Recurse
    In this example "C:\Users\Dropbox\" and "C:\dc01" represent folders. Zip files under every directory level of "C:\Users\Dropbox\" and "C:\dc01" are searched and the contents of every found zip file is extracted under its own folder inside the "C:\Scripts" folder.
  5. ./Unzip-Silently -Source "C:\Windows\a certain archive.zip", "C:\Users\Dropbox\" -Folder -Purge
    Will extract the contents of "C:\Windows\a certain archive.zip" under the folder "C:\Windows\a certain archive". Will also look for zip files to process from the first directory level of "C:\Users\Dropbox\" (as indicated by the common command 'dir C:\Users\Dropbox\' for example), and extracts the contents of every found zip file under its own folder inside the "C:\Users\Dropbox\" directory. After the contents of the zip file(s) has been extracted, the original zip file(s) is/are deleted.

    This command will work, because -Source is an alias of -FilePath and -Folder is an alias of -Include. The -FilePath (a.k.a. -Source a.k.a. -FilenameWithPathName a.k.a. -FullPath a.k.a. -File, a.k.a. -ZipFile, a.k.a. -Zip) variable value is case-insensitive (as is most of the PowerShell), but since the zip filename contains space characters, the whole string (entity) needs to be enveloped with quotation marks. The -Source parameter may be left out from this command, since, for example,

    ./Unzip-Silently "c:\wINDOWs\A Certain Archive.zip", c:\users\dropbox -Folder -Purge

    is the exact same command in nature.
  6. Set-ExecutionPolicy remotesigned
    This command is altering the Windows PowerShell rights to enable script execution for the default (LocalMachine) scope. Windows PowerShell has to be run with elevated rights (run as an administrator) to actually be able to change the script execution properties. The default value of the default (LocalMachine) scope is "Set-ExecutionPolicy restricted".

    Parameters:

      Restricted Does not load configuration files or run scripts. Restricted is the default execution policy.
      AllSigned Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
      RemoteSigned Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
      Unrestricted Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
      Bypass Nothing is blocked and there are no warnings or prompts.
      Undefined Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.

    For more information, please type "Get-ExecutionPolicy -List", "help Set-ExecutionPolicy -Full", "help about_Execution_Policies" or visit Set-ExecutionPolicy or about_Execution_Policies.

  7. New-Item -ItemType File -Path C:\Temp\Unzip-Silently.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force. If the path name and/or the filename includes space characters, please enclose the whole -Path parameter value in quotation marks (single or double):

      New-Item -ItemType File -Path "C:\Folder Name\Unzip-Silently.ps1"

    For more information, please type "help New-Item -Full".

Contributing

Find a bug? Have a feature request? Here is how you can contribute to this project:

contributing Bugs: Submit bugs and help us verify fixes.
Feature Requests: Feature request can be submitted by creating an Issue.
Edit Source Files: Submit pull requests for bug fixes and features and discuss existing proposals.

www

www Script Homepage
Lee Holmes: Windows PowerShell Cookbook (O'Reilly): Get-FileHash script
PowerShell - use shell.application to zip files
New-Object
Directory Methods
Path Methods
Adding a Simple Menu to a Windows PowerShell Script
Test-Path
PowerShell Tutorial – Loops (For, ForEach, While, Do-While, Do-Until)
Perfect Progress Bars for PowerShell
How to zip/unzip files in Powershell?
PowerShell Shell.Application To Launch Windows Explorer
unzip.ps1
Expand-ZipFile
Unzip Files
Get-FileHash.ps1
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Disable-Defrag
Firefox Customization Files
Get-AsciiTable
Get-BatteryInfo
Get-ComputerInfo
Get-CultureTables
Get-DirectorySize
Get-HashValue
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-PowerShellAliasesTable
Get-PowerShellSpecialFolders
Get-RAMInfo
Get-TimeDifference
Get-TimeZoneTable
Get-UnusedDriveLetters
Emoji Table
Java-Update
Remove-DuplicateFiles
Remove-EmptyFolders
Remove-EmptyFoldersLite
Rename-Files
Rock-Paper-Scissors
Toss-a-Coin
Update-AdobeFlashPlayer
Update-MozillaFirefox

About

Unzips zip files to generically named new folders (a Windows PowerShell script).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published