title: Powershell v4.0 "long path" usage
body: <p>How to approach a situation when you have a simple zip like <code>file.zip</code>, but inside you have a file which is longer than the Microsoft's allowed 260 characters (it is actually little bit less but that does not matter in our case)?</p>
  
  <p>If you get from some source (like Google) a file which is, for example, <strong>400</strong> characters long.</p>
  
  <p>How to properly unzip it via powershell in Windows (preferably 7 -> powershell 4.x)?</p>
  
  <p>You could do it via some unzip tool and use the unicode path trick (<code>\\?\</code>) like:</p>
  
  <pre><code>unzip test.zip -d \\?\c:\&lt;path&gt;
  </code></pre>
  
  <p>I would like to do the same via powershell script (version 4.x).</p>
  
  <p>Below is my script (inspired by some others), which normally works.  </p>
  
  <pre><code># .NET Framework 4.5 required (at least PowerShell -Version 2)
  
  Add-Type -AssemblyName System.IO.Compression.FileSystem # -ErrorAction Stop
  
  $source_zip_file= 'C:\&lt;path&gt;\file.zip'
  $destination_directory = 'c:\t\unpack'
  
  # Does NOT support long path!!! with 
  # $destination_directory = '\\?\c:\t\unpack'
  
  $overwrite_destination = $true
  
  $archive = [IO.Compression.ZipFile]::OpenRead($source_zip_file)
  
  foreach ($entry in $archive.entries) {
  
      # better than Join-Path when spaces are present
      $entry_file_path = [System.IO.Path]::Combine($destination_directory, $entry.FullName)
  
      $entry_directory = [System.IO.Path]::GetDirectoryName($entry_file_path)
  
       # create destination directory if not present
       If (!(Test-Path $entry_directory)) {
            New-Item -ItemType Directory -Path $entry_directory | Out-Null
       }
  
      [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $entry_file_path, $overwrite_destination)
  
  }
  </code></pre>
  
  <p><strong>How to expand it to work with long path <code>\\?\c:</code>?</strong></p>
  
  <p><strong>Edit</strong> - sample file</p>
  
  <p><a href="https://anonfile.com/p94fG6d7b7/1.zip" rel="nofollow noreferrer">https://anonfile.com/p94fG6d7b7/1.zip</a></p>
  
  <p>The error message generated:</p>
  
  <blockquote>
    <p>Exception calling "GetDirectoryName" with "1" argument(s): "The
    specified path, file name, or both are too long. The fully qualified
    file name must be less than 260 characters, and the dir ectory name
    must be less than 248 characters."</p>
  </blockquote>
  
  <p><strong>Edit</strong> due to comments</p>
  
  <p>I'm aware that it will not be easy task and the .NET support is grody. </p>
  
  <p>My idea was that it would be possible like here on the Hey, Scripting Guy! Blog <a href="https://blogs.technet.microsoft.com/heyscriptingguy/2015/12/27/weekend-scripter-remove-a-long-path-file/" rel="nofollow noreferrer">Weekend Scripter: Remove a Long Path File</a> via Windows API.</p>