Sco*_*ben 3 windows 7zip batch-file
I'm using 7-Zip 19.00 64-bit. I want to compress the files in a folder, but exclude sub-directories; disable recursive.
The command that I'm executing:
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\*.*
Run Code Online (Sandbox Code Playgroud)
C:\inetpub\wwwroot\ will have sub-directories in it that are named after domains.
C:\inetpub\wwwroot\domain.com (directory)
C:\inetpub\wwwroot\domain.org (directory)
C:\inetpub\wwwroot\domain.net (directory)
C:\inetpub\wwwroot\images (directory)
C:\inetpub\wwwroot\javascript (directory)
C:\inetpub\wwwroot\index.html
C:\inetpub\wwwroot\robots.txt
C:\inetpub\wwwroot\favicon.ico
Run Code Online (Sandbox Code Playgroud)
7-Zip is including sub-directories that match the wildcard; domain.com, domain.org, domain.net will be in wwwroot.7z. images and javascript will be excluded. index.html, robots.txt, and favicon.ico will be in wwwroot.7z as expected.
Because the folders for sites/domains will change over time, I can't hard-code the list of folders to exclude.
I've tried to use the following and none of them work as I want:
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\.
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\
Run Code Online (Sandbox Code Playgroud)
I've looked in the documentation for ways to exclude by attribute but couldn't find it. I've looked at the -x option, but it only seems to apply to files.
The system that I'm running this on is Windows Server 2012 R2.
@Mofi: wwwroot.7z should only contain files, No sub-directories.
To accomplish this task with WinRAR, I'd use this command:
rar u -ma5 -m5 -ep1 C:\inetpub\wwwroot\wwwroot.rar C:\inetpub\wwwroot\*.*
Run Code Online (Sandbox Code Playgroud)
仅将指定目录中的文件非递归压缩为 7-Zip 存档的解决方案是:
7z.exe u -mx9 -bd -x!*\ -- wwwroot.7z C:\inetpub\wwwroot\*
Run Code Online (Sandbox Code Playgroud)
该开关-x!*\导致 e x包括目录中的所有目录C:\inetpub\wwwroot以及这些目录中的所有文件。7-Zip 甚至不会尝试访问使用此开关的子目录之一,因为可以通过 Sysinternals (Microsoft) 免费工具Process Monitor看到它。
*使用通配符来代替*.*将没有文件扩展名的文件压缩到存档文件中。7-Zip 帮助页面命令行语法解释了与 Windows 之间的区别*和*.*比较,Windows*.*总是解释为*. WinRAR 的解释*.*也与*7-Zip 不同,因此与 Windows 相比也不同。
注意:我不明白为什么默认开关-r-即使在命令行上显式使用也不会导致忽略所有子目录中的所有文件,因为它应该根据帮助页面上的说明-r(递归子目录)使用 7-Zip开关19.00(x86 或 x64 版本)。-r-致力于使用*.txt而不仅仅是*. 因此,使用通配符模式*或*.*使用隐式默认值-r-或在命令行上显式指定此开关时在子目录中添加文件的行为看起来要么是 7-Zip 19.00 的错误,要么是一个不好记录的行为(如果有意)设计。