如何使用 Windows 批处理文件将多个文件压缩为每个存档 3 个文件?

发布于 2024-12-05 05:46:12 字数 281 浏览 0 评论 0原文

我有 100 个如下所示的文件:

001.txt
002.txt
003.txt
004.txt
.....
100.txt

我想像这样压缩它们:

001.txt
002.txt ----> archive01.7z
003.txt
---------
004.txt
005.txt ----> archive02.7z
006.txt

如何使用 Windows 批处理文件实现此目的?提前致谢:D

I have 100 files that look like this:

001.txt
002.txt
003.txt
004.txt
.....
100.txt

I want to compress them like this:

001.txt
002.txt ----> archive01.7z
003.txt
---------
004.txt
005.txt ----> archive02.7z
006.txt

How can I achieve this with windows batch file?Thanks in advance:D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄断弥空 2024-12-12 05:46:12
@echo off
setlocal enabledelayedexpansion
rem initialize all variables
set counter=1
set groupnumber=1
rem change groupcount value if you want a different number of files per zip
set groupcount=3
set zipfilenamePrefix=archive
rem start looping over...
for %%f in (*) do (
    if not "%%f"=="%~nx0" (
        set fileList=!fileList! %%f
        set /a reminder=!counter!%%!groupcount!
        if !reminder! equ 0 (
            set zipfilename=archive!groupnumber!.tz
            echo Zipping files: !fileList! into !zipfilename!
            rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
            set /a groupnumber=!groupnumber!+1
            set fileList=
        )
        set /a counter=counter+1
    )
)
rem there could be some left over files - last group may be less than 3 files
if !reminder! equ 0 (
    set zipfilename=archive!groupnumber!.tz
    echo Zipping into files: !fileList! !zipfilename!
    rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
)
@echo off
setlocal enabledelayedexpansion
rem initialize all variables
set counter=1
set groupnumber=1
rem change groupcount value if you want a different number of files per zip
set groupcount=3
set zipfilenamePrefix=archive
rem start looping over...
for %%f in (*) do (
    if not "%%f"=="%~nx0" (
        set fileList=!fileList! %%f
        set /a reminder=!counter!%%!groupcount!
        if !reminder! equ 0 (
            set zipfilename=archive!groupnumber!.tz
            echo Zipping files: !fileList! into !zipfilename!
            rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
            set /a groupnumber=!groupnumber!+1
            set fileList=
        )
        set /a counter=counter+1
    )
)
rem there could be some left over files - last group may be less than 3 files
if !reminder! equ 0 (
    set zipfilename=archive!groupnumber!.tz
    echo Zipping into files: !fileList! !zipfilename!
    rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文