7-Zip 关闭匹配 *.* 的文件夹的递归
7-Zip turn off recursive for folders that match *.*
我正在使用 7-Zip 19.00 64 位。我想压缩文件夹中的文件,但不包括子目录;禁用递归。
我正在执行的命令:
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\*.*
C:\inetpub\wwwroot\ 将包含以域命名的子目录。
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
7-Zip 包含与通配符匹配的子目录; domain.com、domain.org、domain.net 将在 wwwroot.7z 中。图片和 javascript 将被排除。 index.html、robots.txt 和 favicon.ico 将按预期位于 wwwroot.7z 中。
因为 sites/domains 的文件夹会随着时间的推移而改变,我无法硬编码要排除的文件夹列表。
我已经尝试使用以下内容,并且 none 可以正常工作:
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\.
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\
我在文档中查找了按属性排除的方法,但找不到。我查看了 -x 选项,但它似乎只适用于文件。
我 运行 使用的系统是 Windows Server 2012 R2。
@Mofi: wwwroot.7z 应该只包含文件,没有子目录。
要用 WinRAR 完成这个任务,我会使用这个命令:
rar u -ma5 -m5 -ep1 C:\inetpub\wwwroot\wwwroot.rar C:\inetpub\wwwroot\*.*
@echo off
setlocal
set "target=C:\inetpub\wwwroot"
dir /b /a-d "%target%\*" > "%cd%\include.tmp"
pushd "%target%\" && (
call 7z u -mx9 -bd "%cd%\wwwroot.7z" -ir0@"%cd%\include.tmp"
popd
)
del "%cd%\include.tmp"
可以使用dir
的输出创建一个列表文件,它可以给出一个文件列表。 pushd
进入目标目录并运行7z
。 %cd%
将保持不变,因为不使用延迟扩展,即 !cd!
。如果您想要脚本目录而不是当前目录,请将 %cd%
更改为 %~dp0
。
列表文件可为您提供所需的灵活性。
仅将指定目录中的文件非递归压缩为 7-Zip 压缩包的解决方案是:
7z.exe u -mx9 -bd -x!*\ -- wwwroot.7z C:\inetpub\wwwroot\*
开关 -x!*\
导致 ex 包括目录 C:\inetpub\wwwroot
中的所有目录和这些目录中的所有文件。 7-Zip 甚至不尝试访问使用此开关的子目录之一,因为可以使用 Sysinternals (Microsoft) 免费工具 Process Monitor.
使用通配符 *
而不是 *.*
将没有文件扩展名的文件压缩到存档文件中。 7-Zip 帮助页面 命令行语法 解释了 *
和 *.*
与始终解释 *.*
的 Windows 之间的区别喜欢 *
。 WinRAR 解释 *.*
也不同于 *
,如 7-Zip,因此与 Windows 相比也不同。
注意: 我不明白为什么默认开关 -r-
即使在命令行上显式使用也不会导致忽略所有子目录中的所有文件,因为它应该根据帮助页面 -r (Recurse subdirectories) switch 上的说明使用 7-Zip 19.00(x86 或 x64 版本)。 -r-
致力于使用 *.txt
而不仅仅是 *
。所以看起来在使用通配符模式 *
或 *.*
的子目录中添加文件时使用隐式默认值 -r-
或在命令行上显式指定此开关的行为是7-Zip 19.00 的错误或有意设计的不良记录行为。
我正在使用 7-Zip 19.00 64 位。我想压缩文件夹中的文件,但不包括子目录;禁用递归。
我正在执行的命令:
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\*.*
C:\inetpub\wwwroot\ 将包含以域命名的子目录。
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
7-Zip 包含与通配符匹配的子目录; domain.com、domain.org、domain.net 将在 wwwroot.7z 中。图片和 javascript 将被排除。 index.html、robots.txt 和 favicon.ico 将按预期位于 wwwroot.7z 中。
因为 sites/domains 的文件夹会随着时间的推移而改变,我无法硬编码要排除的文件夹列表。
我已经尝试使用以下内容,并且 none 可以正常工作:
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\.
7z u -mx9 -r- -bd wwwroot.7z C:\inetpub\wwwroot\
我在文档中查找了按属性排除的方法,但找不到。我查看了 -x 选项,但它似乎只适用于文件。
我 运行 使用的系统是 Windows Server 2012 R2。
@Mofi: wwwroot.7z 应该只包含文件,没有子目录。
要用 WinRAR 完成这个任务,我会使用这个命令:
rar u -ma5 -m5 -ep1 C:\inetpub\wwwroot\wwwroot.rar C:\inetpub\wwwroot\*.*
@echo off
setlocal
set "target=C:\inetpub\wwwroot"
dir /b /a-d "%target%\*" > "%cd%\include.tmp"
pushd "%target%\" && (
call 7z u -mx9 -bd "%cd%\wwwroot.7z" -ir0@"%cd%\include.tmp"
popd
)
del "%cd%\include.tmp"
可以使用dir
的输出创建一个列表文件,它可以给出一个文件列表。 pushd
进入目标目录并运行7z
。 %cd%
将保持不变,因为不使用延迟扩展,即 !cd!
。如果您想要脚本目录而不是当前目录,请将 %cd%
更改为 %~dp0
。
列表文件可为您提供所需的灵活性。
仅将指定目录中的文件非递归压缩为 7-Zip 压缩包的解决方案是:
7z.exe u -mx9 -bd -x!*\ -- wwwroot.7z C:\inetpub\wwwroot\*
开关 -x!*\
导致 ex 包括目录 C:\inetpub\wwwroot
中的所有目录和这些目录中的所有文件。 7-Zip 甚至不尝试访问使用此开关的子目录之一,因为可以使用 Sysinternals (Microsoft) 免费工具 Process Monitor.
使用通配符 *
而不是 *.*
将没有文件扩展名的文件压缩到存档文件中。 7-Zip 帮助页面 命令行语法 解释了 *
和 *.*
与始终解释 *.*
的 Windows 之间的区别喜欢 *
。 WinRAR 解释 *.*
也不同于 *
,如 7-Zip,因此与 Windows 相比也不同。
注意: 我不明白为什么默认开关 -r-
即使在命令行上显式使用也不会导致忽略所有子目录中的所有文件,因为它应该根据帮助页面 -r (Recurse subdirectories) switch 上的说明使用 7-Zip 19.00(x86 或 x64 版本)。 -r-
致力于使用 *.txt
而不仅仅是 *
。所以看起来在使用通配符模式 *
或 *.*
的子目录中添加文件时使用隐式默认值 -r-
或在命令行上显式指定此开关的行为是7-Zip 19.00 的错误或有意设计的不良记录行为。