问题描述
我正在尝试让我的 powershell 脚本压缩一些文件和文件夹.目前我可以让我的脚本压缩所有文件(不包含文件夹),或者压缩包含文件夹但到错误路径的所有文件.例如,如果我有一个名为 wordpress 的文件夹,其中包含文件和几个子文件夹.我需要我的 zip 文件是 wordpress.zip,所有文件和子文件夹都在该 zip 的根目录中,而不是 wordpressfiles.*
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 wordpressfiles.*
任何帮助将不胜感激.到目前为止,这是我的代码
Any help would be appreciated. Here is my code so far
function create-7zip([String] $aDirectory, [String] $aZipfile){
[string]$pathToZipExe = "C:Program Files7-zip7z.exe";
[Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
& $pathToZipExe $arguments;
}
create-7zip "$storageDirwordpress*.*" "$storageDirwordpress.zip"
上面的例子只会压缩我的目标文件夹中的文件,我需要它来包含子文件夹.
The above example will only zip files inside of my target folder, I need it to include the subfolders as well.
推荐答案
create-7zip "$storageDirwordpress*" "$storageDirwordpress.zip"
将包含文件和子文件夹.
will include files and subfolders.
这篇关于如何使用 7zip powershell 包含文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!