frosty8612

Zip unarchival

Jun 16th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -AssemblyName System.Windows.Forms # Only need this once
  2.  
  3. Function get-files{
  4.     $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
  5.         InitialDirectory = '\\networkshare\someshare'
  6.         Filter = 'zip (*.zip)|*.zip'
  7.         Multiselect = $true
  8.       }
  9.     [void]$FileBrowser.ShowDialog()
  10.     $FileBrowser.FileNames
  11.   }
  12.  
  13. Function Move-files {
  14.     $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
  15.         SelectedPath = 'D:\TMP'
  16.       }
  17.     [void]$FolderBrowser.ShowDialog()
  18.     $FolderBrowser.SelectedPath
  19.   }
  20.  
  21. # Define Vars upfront
  22.  $openfile = get-files
  23.  $movefile = Move-files
  24.  $tempFldr = "D:\TMP"
  25.  
  26. # Make sure the TMP folder exists first
  27.  IF (!(Test-Path D:\TMP)) { New-Item -Path D: -Name TMP -Type Directory | Out-Null}
  28.  
  29. # Multiselect is true above, so if there are multiple zips, this will handle each, one at a time
  30.  Foreach ($file in $openfile) {
  31.     $folder = ($file.Split(".")).split("\")[1]
  32.     Expand-Archive -Path $file -DestinationPath $tempFldr -Force
  33.     New-Item -Path $movefile -Name $folder -ItemType Directory | Out-Null
  34.     Copy-Item $tempFldr\*.* -Exclude *.zip -Destination $movefile\$folder
  35.     Remove-Item E:\TMP -Recurse
  36.   }
Advertisement
Add Comment
Please, Sign In to add comment