问题描述
我正在尝试使我的Powershell脚本压缩一些文件和文件夹。目前,我可以使脚本压缩所有文件(不包括文件夹),或压缩所有包含文件夹但文件路径错误的文件。
例如,如果我有一个名为wordpress的文件夹,其中包含文件和一些子文件夹。我需要我的zip文件是wordpress.zip,所有文件和子文件夹都在该zip的根目录中,而不是\wordpress\files。*
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.
推荐答案
create-7zip "$storageDir\wordpress\*" "$storageDir\wordpress.zip"
将包括文件和子文件夹。
will include files and subfolders.
这篇关于如何使用7zip Powershell包含文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!