tglogo.png
0 LIKES

Snippet


/unzip & $unzip() v1.1 by ^WeSt

In Category General IRC Posted by Snippets On 12/06/23
Tags: unzip west 

This is an usefull alias/identifier that allowing you to unzip/extract an ZIP file (and only .zip file) into a specific destination/folder without any extra tools by using Windows functions, it was tested under mirc 7.52 on Windows 10 and working, i am not sure if it is working on other windows versions.
Usage:

/unzip [-do]
(It will echo an successfully message if succeed otherwise an error message will occurr)
Note: You can use the /.unzip command thought to unzip/extract the ZIP File to not get any echo messages back!

-d (optional) = Will delete the ZIP File when extracting finishes successfully.
-o (optional) = Will open the Destination Folder when extracting finishes successfully.

$unzip(ZIP File,Destinaton Folder).[destroy open]
(If the unzip/extract succeed then it will return 'SUCCESS' message back, otherwise it will return zero)

.destroy (optional) = Will delete the ZIP File when extracting finishes successfully.
.open (optional) = Will open the Destination Folder when extracting finishes successfully.
Examples:

/unzip "C:\Users\westor\Downloads\test.zip" "C:\Users\westo\Downloads\test_folder\"
/.unzip "C:\Users\westor\Downloads\test.zip" "C:\Users\westo\Downloads\test_folder\"
/unzip -d "C:\Users\westor\Downloads\test.zip" "C:\Users\westo\Downloads\test_folder\"
/unzip -o "C:\Users\westor\Downloads\test.zip" "C:\Users\westo\Downloads\test_folder\"
/unzip -do "C:\Users\westor\Downloads\test.zip" "C:\Users\westo\Downloads\test_folder\"

//echo -a Unzip progress: $unzip(C:\Users\westor\Downloads\test.zip,C:\Users\westo\Downloads\test_folder)
//echo -a Unzip progress: $unzip(C:\Users\westor\Downloads\test.zip,C:\Users\westo\Downloads\test_folder).destroy
//echo -a Unzip progress: $unzip(C:\Users\westor\Downloads\test.zip,C:\Users\westo\Downloads\test_folder).open
//echo -a Unzip progress: $iif($unzip($mircdirdownloads\test.zip,$mircdirdownloads),OK,ERROR)
alias unzip {
  if (!$isid) {
    if (-* iswm $1) {
      if (!$remove($1,-)) { $iif($show,echo -eac info * /unzip: Missing specified flags values parameters!) | return }
      if (*d* !iswmcs $1) && (*o* !iswmcs $1) { $iif($show,echo -eac info * /unzip: Incorrect specified flags!) | return }
    }
    if (-* iswm $1) {
      var %flags = $remove($1,-)
      var %zip = $gettok($2-,1,34)
      var %dest = $gettok($2-,3,34)
      if ($count($2-,$chr(34)) !== 4) { $iif($show,echo -eac info * /unzip: Please specify $qt() characters in every locations parameter!) | return }
    }
    elseif (-* !iswm $1) {
      var %zip = $gettok($1-,1,34)
      var %dest = $gettok($1-,3,34)
      if ($count($1-,$chr(34)) !== 4) { $iif($show,echo -eac info * /unzip: Please specify $qt() characters in every locations parameter!) | return }
    }

    if (!%zip) || (!$remove(%zip,$chr(32))) { $iif($show,echo -eac info * /unzip: Not enough parameters, Please specify the ZIP file!) | return }
    if (!%dest) || (!$remove(%dest,$chr(32))) { $iif($show,echo -eac info * /unzip: Not enough parameters, Please specify a destination folder!) | return }
    if (!$isfile(%zip)) { $iif($show,echo -eac info * /unzip: The ZIP file location does not exists!) | return }
    if (!$isdir(%dest)) { $iif($show,echo -eac info * /unzip: The unzipping/extracting destination folder does not exists!) | return }
    if ($right(%zip,4) !== .zip) { $iif($show,echo -eac info * /unzip: Please specify only $qt(.zip) files for unzipping/extracting!) | return }

  }
  elseif ($isid) {
    if (!$1) { return 0 }
    if (!$2) { return 0 }
    if (!$isfile($1)) { return 0 }
    if (!$isdir($2)) { return 0 }
    if (*.zip* !iswm $1-) { return 0 }
    if ($prop) && (!$istok(destroy open,$prop,32)) { return 0 }

    var %zip = $1
    var %dest = $2
  } 

  var %n = Unzip_ $+ $ticks $+ $ctime
  if ($com(%n)) { .comclose %n }

  var %data = $&
    ZipFile= $+ $qt(%zip) $lf $&
    ExtractTo= $+ $qt(%dest) $lf $&
    Set fso = CreateObject("Scripting.FileSystemObject") $lf $&
    sourceFile = fso.GetAbsolutePathName(ZipFile) $lf $&
    destFolder = fso.GetAbsolutePathName(ExtractTo) $lf $&
    Set objShell = CreateObject("Shell.Application") $lf $&
    Set FilesInZip=objShell.NameSpace(sourceFile).Items() $lf $&
    objShell.NameSpace(destFolder).CopyHere FilesInZip, 4 Or 16 $lf $&
    Set fso = Nothing $lf $&
    Set objShell = Nothing $lf $&
    Set FilesInZip = Nothing

  .comopen %n MSScriptControl.ScriptControl
  if ($comerr) { 
    if ($com(%n)) { .comclose $v1 }
    if ($isid) { return 0 }
    elseif (!$isid) { $iif($show,echo -eac info * /unzip: There was a connection problem while trying to creating a COM!) | return }
  }

  var %r = $calc($com(%n,language,4,bstr*,vbscript) + $com(%n,executestatement,1,bstr*,%data))
  if ($comerr) { 
    if ($com(%n)) { .comclose $v1 }
    if ($isid) { return 0 }
    elseif (!$isid) { $iif($show,echo -eac info * /unzip: There was a writing problem while trying to creating a COM!) | return }
  }

  if (%flags) && (*o* iswm %flags) && (%r == 2) { run $qt(%dest) }
  if (%flags) && (*d* iswm %flags) && (%r == 2) && ($isfile(%zip)) { .remove $qt(%zip) }
  if ($isid) && ($prop) && ($prop == open) && (%r == 2) { run $qt(%dest) }
  if ($isid) && ($prop) && ($prop == destroy) && (%r == 2) { .remove $qt(%zip) }

  if ($com(%n)) { .comclose $v1 }

  if ($isid) { return $iif(%r == 2,SUCCESS,0) }
  if (!$isid) && ($show) { echo -eac info * /unzip: The ZIP file $qt(%zip) has been extracted on $qt(%dest) destination. }

  return
  :error
  if ($com(%n)) { .comclose $v1 }
  if ($isid) && ($error) { reseterror | return 0 }
  if (!$isid) && ($error) && ($show) { echo -eac info * /unzip: Scripting Error, $error | reseterror }
}


Comments 0


Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand