How to include files and folders with 7zip powershell

天涯浪子 提交于 2019-12-07 03:13:16

问题


Im trying to make my powershell script zip up a few files and folders. At the moment I can make my script either zip all files (with no folders included), or zip all files with folders included but to the wrong path. An example would be if I have a folder named wordpress with files and a few subfolders. I need my zip file to be wordpress.zip, with all files and subfolders being in the root of that zip as opposed to \wordpress\files.*

Any help would be appreciated. Here is my code so far

function create-7zip([String] $aDirectory, [String] $aZipfile){
    [string]$pathToZipExe = "C:\Program Files\7-zip\7z.exe";
    [Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
    & $pathToZipExe $arguments;
}

create-7zip "$storageDir\wordpress\*.*"  "$storageDir\wordpress.zip"

The above example will only zip files inside of my target folder, I need it to include the subfolders as well.


回答1:


create-7zip "$storageDir\wordpress\*"  "$storageDir\wordpress.zip"

will include files and subfolders.



来源:https://stackoverflow.com/questions/10759262/how-to-include-files-and-folders-with-7zip-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!