<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aizaz Ahmad</title>
    <description>The latest articles on Forem by Aizaz Ahmad (@aizazahmad).</description>
    <link>https://forem.com/aizazahmad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F712250%2F31764ea8-2191-4abe-aa25-615f251c13ef.jpeg</url>
      <title>Forem: Aizaz Ahmad</title>
      <link>https://forem.com/aizazahmad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aizazahmad"/>
    <language>en</language>
    <item>
      <title>Compress Folders like a PRO (Window)</title>
      <dc:creator>Aizaz Ahmad</dc:creator>
      <pubDate>Tue, 28 Sep 2021 06:21:15 +0000</pubDate>
      <link>https://forem.com/aizazahmad/compress-folders-like-a-pro-window-1ngb</link>
      <guid>https://forem.com/aizazahmad/compress-folders-like-a-pro-window-1ngb</guid>
      <description>&lt;p&gt;Bored of using the GUI to Compress the folders? Then you have come to the right Blog that will change the way you Compress your folders/files forever. Today, I will be covering how to use Windows PowerShell to Compress the Folder/File and also exclude or Include specific folders/files while Compressing folders.&lt;/p&gt;




&lt;h3&gt;
  
  
  Simple Compression Operation
&lt;/h3&gt;

&lt;p&gt;Open up Windows PowerShell and type in the &lt;code&gt;Compress-Archive&lt;/code&gt; Command following the below Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;path/to/folder/file&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Compresed_File_name&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Path to the Folder/File can be both Absolute or Relative. You can also navigate to the Parent Folder of the File or Folder you want to Compress using the &lt;code&gt;cd&lt;/code&gt; command and run the Command here too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Examples
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To Create a Compressed ZIP file with name 'assets.zip' of 'images' folder inside the cwd (Assuming that we have already navigated to the parent Folder of 'images')&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;assets&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Similarly for a file named 'img.png', while creating 'images.zip' inside the 'dir' folder the command will look like this:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;img.png&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dir/image&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Now, You will be like, Aizaz, WTH, What's Interesting in this? I can like get the above work done in just 2 clicks and you are asking me to write these Scary Commands to get the work done. Yes, you are right but these are just the basic stuff. I will be now explaining more interesting and amazing parts of it. &lt;/p&gt;




&lt;h3&gt;
  
  
  Creating a Single ZIP file from Multiple Folders/Files
&lt;/h3&gt;

&lt;p&gt;Using the above same command, We can also create a single ZIP file from multiple resources (Folders/Files) by using the command with the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;@(&lt;/span&gt;&lt;span class="s1"&gt;'./path/to/1st/resource'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'path/to/2nd/resource'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Compresed_File_name&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;@(&lt;/span&gt;&lt;span class="s1"&gt;'file.txt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'folder-1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'folder-2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dir/example&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a'example.zip' file inside the 'dir' folder with file.txt, folder-1, and folder-2 compressed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This above Syntax can be used to choose specific files/folders inside a folder to be included in the archive. Just navigate to the folder containing the content you want to Compress and specify the files you want to include in the ZIP file.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Creating ZIP file Excluding Specific files/folders
&lt;/h3&gt;

&lt;p&gt;There comes many situations where one has to exclude particular files/folders while creating a ZIP file. One kind of situation is when one has to send the Archive (Zip File) of a JavaScript Application that has node_modules installed, but one can't afford node_modules to be included inside a ZIP file as it will be troublesome to send such a huge file over the internet. One way of Getting Rid of this is to create a new folder and place all files other than node_modules in it and then compress that folder and send it. It Works, but this practice becomes weary when you have to do that again and again after changes in Source Code. But, now that's not the problem anymore.&lt;br&gt;
Use the Following Command to Exclude file/folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Get-ChildItem&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-exclude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;file/folder_to_be_excluded&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-DestinationPath&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Compresed_File_name&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Run this Command after navigating to the directory you want to Compress. &lt;code&gt;Get-ChildItem&lt;/code&gt; displays the list of contents of the Directory. &lt;br&gt;
&lt;code&gt;-exclude&lt;/code&gt; flag followed by the resource name is used to exclude that resource from the list. This list is passed to the &lt;code&gt;Compress-Archive&lt;/code&gt; Command through the pipeline &lt;code&gt;|&lt;/code&gt; that creates the ZIP file at the path specified after the &lt;code&gt;-DestinationPath&lt;/code&gt; command.&lt;/p&gt;
&lt;h4&gt;
  
  
  Examples
&lt;/h4&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Get-ChildItem&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-exclude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;node_modules&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-DestinationPath&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also exclude multiple resources&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;Get-ChildItem&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-exclude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;@(&lt;/span&gt;&lt;span class="s1"&gt;'node_modules'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'assets/img'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-DestinationPath&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use an alias for &lt;code&gt;Get-ChildItem&lt;/code&gt; command to make it simpler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;gci&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-exclude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;@(&lt;/span&gt;&lt;span class="s1"&gt;'node_modules'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'assets/img'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Compress-Archive&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-DestinationPath&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You can also Check out the documentation of both &lt;a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem"&gt;Get-ChildItem&lt;/a&gt; and &lt;a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive"&gt;Compress-Archive&lt;/a&gt; Commands to get detailed insight of these.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Thank you for your time and attention!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>zip</category>
      <category>productivity</category>
      <category>archive</category>
      <category>powerfuldevs</category>
    </item>
  </channel>
</rss>
