Is it possible to create a zip archive using PowerShell?
相关问题
- How to Debug/Register a Permanent WMI Event Which
- How can I do variable substitution in a here-strin
- How to use a default value with parameter sets in
- Does powershell have a method_missing()?
- Invoking Mirth Connect CLI with Powershell script
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- C#调用PowerShell的问题
- EscapeDataString having differing behaviour betwee
- PowerShell Change owner of files and folders
- Command line escaping single quote for PowerShell
- Is there a simple way to pass specific *named* Pow
- How do I access an element with xpath with a names
- How to 'Grant Permissions' Using Azure Act
In case you have WinRAR installed:
The meaning of the arguments: afzip creates zip archive, df deletes files, ep1 does not create full directory path within archive
Here a complete command line example to launch from cmd.exe or from ssh or what you want !
Regards
Here is a slightly improved version of sonjz's answer,it adds an overwrite option.
Why does no one look at the documentation?? There's a supported method of creating an empty zip file and adding individual files to it built into the same .NET 4.5 library everyone is referencing.
See below for a code example:
I encourage you to browse the documentation if you have any questions.
Install 7zip (or download the command line version instead) and use this PowerShell method:
You can the call it like this:
Loading the
[System.IO.IOException]
class and using its methods is an important step in order to suppress unwanted errors, due the fact that it's a class not native to PowerShell, so expect various contexts of errors without it.I error-controlled my script to the T, but got a lot of extra red 'file exists' output while using
[System.IO.Compression.ZipFile]
classWhat I am doing here is catching these IO Errors, such as accessing files that exist already, catching that error and directing it to a logfile that I am maintaining with a larger program.