From WikiChip
Editing mirc/identifiers/$zip

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 1: Line 1:
 
{{mirc title|$zip Identifier}}'''$zip''' creates/tests/extracts/lists zip using optional AES-256 encryption
 
{{mirc title|$zip Identifier}}'''$zip''' creates/tests/extracts/lists zip using optional AES-256 encryption
 
'''Note''': You cannot edit an existing zip file currently.
 
  
 
== Synopsis ==
 
== Synopsis ==
<pre>
+
<pre>$zip(file.zip,<c|e|t|l>[po],file|dir|N [,password])[.size]
$zip(file.zip,c[po],<filename/folder>[,password])
+
$zip(file.zip,c[po],file|dir added [,password])
 
$zip(file.zip,l,N)[.size]
 
$zip(file.zip,l,N)[.size]
 
$zip(file.zip,t[p,password])
 
$zip(file.zip,t[p,password])
$zip(file.zip,e[po],<extractdir> [,password])
+
$zip(file.zip,e[po],ExtractDir [,password])
 
</pre>
 
</pre>
 +
== Parameters ==
 +
* '''file.zip''' = filename used to create the .zip (or overwrite existing file when using o switch)
 +
* '''cetpol''' = see valid switches below
 +
* '''file|dir''' = different meaning in different c|e|l contexts:
 +
** when c switch used, if this is a filename, this is the 1 file to be added without including path. Wildcards not accepted. If this is a foldername, the contents of that folder and any subfolders are added to file.zip with relative path beginning with "dirname\"
 +
** When e switch used, is the destination FOLDER for extraction of all contents of file.zip.
 +
** When l switch is used, this is the filename.zip whose contents are listed (listed items can be filenames or foldernames)
 +
** When 't' switch is used, does not permit using the file|dir parameter
 +
'''N = 0''' lists the total number of items
 +
'''N > 0''' returns the Nth item inside the zip
 +
* password = password used to encrypt each file added to zip. Can contain spaces. Valid only when using the 'p' switch.
 +
Note: when 't' testing the .zip, the file|dir parameter is not present, and 'p' causes the 3rd parameter to be seen as password<br />
 +
Note: the password is valid but ignored when 't' tests or 'e' extracts files which had not been encrypted
  
== Parameters ==
+
== Switches ==
* '''file.zip''' - the zip filename you want to create/test/list/extract from
+
* c = create zip
* '''p''' - specify that the [password] parameter has been provided and should be used for the zip file
+
* l = list zip contents (N=0 is total items, N>0 is the Nth item) .size prop lists filesize instead of filename) items ending with "\" are foldernames whose .size is zero)
* '''o''' - overwrite the zip file when creating, overwrite the existing files and folder when extracting. It is also required if you extract into an empty existing folder (watch out)
+
* e = extract from zip
 +
* p = password
 +
* t = test zip contents
 +
* o = overwrite extraction dir & contents (required if extraction dir exists)
  
* '''c''' - create a zip file and add a file name <filename> or the folder <folder> and all its subfolders.
+
Returns 1=success 0=fail except when 'l'isting
* '''l''' - list the content of the zip file, returns the Nth file/folder or the total of elements in the zip
 
* '''t''' - test the zip file
 
* '''e''' - extract all the content of the zip to the <extractdir> folder
 
  
* '''N''' - used with '''l''' only, lists the Nth file/folder, or the total number of items with N = 0
+
* Warning: Using the 'o' switch when extracting should NOT be used when extracting into $mircdir or any folder having important files in that folder or in any subfolders below it, especially if the zip was not created by YOU. The 'o' switch is required when extracting into an existing foldername, even if empty. However it also results in overwriting extracted contents on top of existing filenames or path\filenames relative to the parent folder of the folder being extracted into.
* '''<file/folder>''' - used with '''c''', the file/folder to add to the created zip file
 
* '''<extractdir>''' - used with '''e''', the folder to extract the zip's content to
 
* '''[password]''' = password used to encrypt or decrypt each file added to zip. Can contain spaces. Valid only when using the 'p' switch.
 
  
 +
Note: If .zip contains a potentially dangerous filename such as containing '../' then 'e' and 'l' report 0 and refuse to extract or list contents.
 
== Properties ==
 
== Properties ==
* '''.size''' - used with '''l''' only, makes $zip returns the size of the file (or 0 for a folder) instead of the filename
+
.size = alters 'l' output to return the Nth item's filesize instead of its filename (If the Nth item is a foldername, returns 0)
* '''.mtime''' - used with '''l''' only, makes $zip returns the timestamp of the file instead of the filename, as an integer which can be changed to date format using $asctime
+
None
* '''.crc''' - used with '''l''' only, makes $zip returns the crc32 of the file instead of the filename, as an integer instead of the hex format of $crc32()
 
* '''.em''' - used with '''l''' only, makes $zip returns 128 or 256 indicating the type of AES encryption. For non-encrypted files returns 0
 
 
 
If '''l''' is not used, $zip returns 1 for success and 0 for failure.
 
 
 
'''Note''': If .zip contains a potentially dangerous filename such as containing '../' then 'e' and 'l' return 0 and refuse to extract or list contents.
 
 
 
'''Warning''': Using the 'o' switch when extracting should NOT be used when extracting into $mircdir or any folder having important files in that folder or in any subfolders below it, especially if the zip was not created by YOU. $zip does not permit you to extract from the .zip into an existing foldername, even if it's empty. However, once you do use the 'o' switch, it allows you to extract into an existing foldername AND it also overwrites all matching files.
 
 
 
 
== Example ==
 
== Example ==
  
Line 81: Line 81:
 
Note: If the password is missing/wrong for a file inside the zip, any foldernames in the zip are created.
 
Note: If the password is missing/wrong for a file inside the zip, any foldernames in the zip are created.
  
Create logs.zip containing contents of logs subfolder beneath $mircdir, returns 1 if successful. If log.zip already exists, returns 0 failure because it will not overwrite the .zip without using the 'o' switch.
+
Create logs.zip containing contents of logs subfolder beneath $mircdir, returns 1 if successful
<source lang="mIRC">
 
 
//echo -a $zip(logs.zip,c,logs)
 
//echo -a $zip(logs.zip,c,logs)
</source>
 
  
 
<source lang="mIRC">
 
<source lang="mIRC">
You can use the 'l' switch to confirm whether there are more than 1 file inside the .zip, and can use the .mtime and .crc properties to compare against other files to compare whether the file inside the .zip is the same. You cannot selectively unzip 1 file out of the zip, so if you need mIRC to extract 1 file for you, you must extract everything into a dummy folder in order to access just the 1 file you need.
 
 
 
List contents of logs.zip:
 
List contents of logs.zip:
//var %i 1 | while ($zip(logs.zip,l,%i)) { echo -a $ord(%i) item: $base($zip(logs.zip,l,%i).crc,10,16,8) $asctime($zip(logs.zip,l,%i).mtime,yyyy/mm/dd HH:nn:ss) $v1 | inc %i }
+
//var %i 1 | while ($zip(logs.zip,l,%i)) { echo -a $ord(%i) item: $v1 | inc %i }
 
Note that the 1st item was the name of the folder, indicated by the trailing backslash
 
Note that the 1st item was the name of the folder, indicated by the trailing backslash
 
</source>
 
</source>
 
== Notes ==
 
 
Note how the files are contained inside the zip as 'logs\filename', and the only way to extract those files to the original path is to make $mircdir be the extract-to folder, which of course you should not do without examining the .zip's contents to ensure that there are no files which would extract to another folder outside the 'logs' folder. To extract safely, you should extract from the zip to a DUMMY folder, which will make these files extract to DUMMY\logs\filenames from where you can copy or move files to where you want them to be, and then delete the DUMMY folder when finished.<br>
 
 
If the 'l' switch confirms that a file exists inside the .zip and extraction fails, be sure whether you need to use the 'o' switch to both extract to a foldername which already exists, as well as to overwrite any files existing within that folder.<br>
 
 
Also note that the return value of 0 indicates that it failed to extract ALL files from the zip. If you extract without a password and the .zip contains a mix of passworded and unpassworded files, the unpassworded ones will extract while the passworded ones will not, causing the '0' return value.<br>
 
 
You can also use $zip(zipfile.zip,l,1).em to verify whether the 1st file in a zip has been encrypted, which requires using the 'p' password switch to extract it. While $zip cannot create files with AES-128 level of encryption, it can extract them from such a .zip created elsewhere. However, note that a .zip can contain files encrypted using the old PKZIP 2.0 encryption method, and .em returns 0 as if they're not encrypted, but $zip cannot extract using the encryption methods other than AES.<br>
 
 
$zip cannot add any file attribute to the files it adds, including hidden/read-only, and if these file attributes were added to files in a .zip created elsewhere, $zip extracts them without any attributes except the 'a' archive flag.
 
  
 
== Compatibility ==
 
== Compatibility ==
{{mIRC compatibility|7.55}}
+
7.55
 
 
 
== See Also ==
 
== See Also ==
 
{{collist
 
{{collist

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)