V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sjmcefc2
V2EX  ›  程序员

求教 7zip 如何利用命令行来压缩某路径下的特定文件夹?

  •  
  •   sjmcefc2 · 2022-12-02 17:00:48 +08:00 · 1537 次点击
    这是一个创建于 509 天前的主题,其中的信息可能已经有所发展或是发生改变。
    E:
    |-A1
    | |-c_M202210_(随机数串)
    | |-c_M202209_(随机数串)
    | |-c_M202208_(随机数串)
    | |-c_M202207_(随机数串)
    |-A2
    | |-c_M202210_(随机数串)
    | |-c_M202209_(随机数串)
    | |-c_M202208_(随机数串)
    
    
    

    想利用命令行把包含 M202210 的文件夹打包,怎么做呢

    6 条回复    2022-12-16 15:38:34 +08:00
    lchynn
        1
    lchynn  
       2022-12-02 20:59:05 +08:00
    set copy_target_path=e:\A1\c_M202210_\
    set targetfile=*.docx

    for /f "delims=" %%s in ('dir /b/a-d/s "%target_path%"\"%targetfile%"') do (
    echo %%s
    7z a "%%s.7z" "%%s"
    )
    wizardyhnr
        2
    wizardyhnr  
       2022-12-03 00:06:56 +08:00
    -i Include filenames a, d, e, l, t, u, x, -r, -x
    -i[<recurse_type>]<file_ref> <recurse_type> ::= r[- | 0] <file_ref> ::= @{listfile} | !{wildcard}

    <recurse_type>
    Specifies how wildcards and file names in this switch must be used. If this option is not given, then the global value, assigned by the -r (Recurse) switch will be used. For more details see specification of the -r (Recurse) switch.

    <recurse_type> ::= r[- | 0]



    <file_ref>
    Specifies filenames and wildcards, or a list file, for files to be processed.

    <file_ref> ::= @{listfile} | !{wildcard}

    Option Description
    {listfile} Specifies name of list file. See List file description.
    {wildcard} Specifies wildcard or filename.
    7z a -tzip src.zip *.txt -ir!DIR1\*.cpp adds to src.zip archive all *.txt files from current directory and all *.cpp files from directory DIR1 and from all it's subdirectories
    leido
        3
    leido  
       2022-12-03 14:16:11 +08:00
    如 2#,7z 的-r 开关就是干这事的。
    sjmcefc2
        4
    sjmcefc2  
    OP
       2022-12-16 11:30:51 +08:00
    @lchynn 这个只能备份 A1,但是也要备份 A2 或者其他的?

    @leido 这个怎么-r 结合到一起吗
    sjmcefc2
        5
    sjmcefc2  
    OP
       2022-12-16 14:22:46 +08:00
    set copy_target_path=e:\A1\c_M202210_\
    set targetfile=*.docx

    for /f "delims=" %%s in ('dir /b/a-d/s "%target_path%"\"%targetfile%"') do (
    echo %%s
    7z a "%%s.7z" "%%s"
    )

    后面可以直接替换成-r 吗
    lchynn
        6
    lchynn  
       2022-12-16 15:38:34 +08:00
    @sjmcefc2 带目录要试一下, 我没试过, 我一般就是用来压缩备份单个文件。用 DIR 筛出后 FOR 循环压缩
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1483 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 17:18 · PVG 01:18 · LAX 10:18 · JFK 13:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.