Please explain set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) line of Powershell Script
After investigating how to create a zip file with Powershell I found the following very helpful link which describes how to create a zip file using Powershell with the following line of script:
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
开发者_StackOverflow
This works like a charm, problem is I simply don't understand how it works. Could I please get a breakdown of what this does?
By using ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
as the value to set-Content
, we are simply adding the file header and creating a 0 byte .zip
file.
To understand this, you may want to read under the section file headers:
- Magic number (programming)
- ZIP (file format)
Headers in ZIP files begin with "PK" (50 4B), the initials of Phil Katz, author of DOS compression utility PKZIP.
精彩评论