分别压缩子文件夹中的文件 [英] Compress separately files within subfolders

查看:203
本文介绍了分别压缩子文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,感谢您的回答,

Hi all and thanks for the answers,

首先,我试图找到问题的答案,但没有找到任何东西。

Firstly, I tried to find the answer to my problem but I did not find anything.

我有一棵文件夹和子文件夹的树,我想使用7zip分别压缩这些文件夹中的文件。

I have a tree of folders and sub-folders and I want to use 7zip to compress the files within those folders separately.

我已经从这个网站上获得了这段代码,它可以实现我想要的功能,但是它将压缩文件放置在主文件夹中:

I have got this piece of code from this very website, it does what I want to get but it places the compressed files on the main folder:

    set extension=.*
    for /R %%a in (*%extension%) do "%sevenzip%" a -mx "%%~na.zip" "%%a"

我想知道是否可以得到一个zip每个文件的文件,并将其放在包含源文件的子文件夹中。或执行上述过程,然后将每个zip文件放在适当的子文件夹中。

I wonder if I can get a zip file of every file and have it in the sub-folder containing the source file. Or doing the process above and place every zip file inside the appropriate sub-folder.

我尝试使用双'For / d',但无法获取:

I tried with a double 'For /d' but I was unable to get it:

    cd /d %~dp0

    rem 7z.exe path

    set sevenzip=

    if "%sevenzip%"=="" if exist "%ProgramFiles(x86)%\7-zip\7z.exe" set 

    sevenzip=%ProgramFiles(x86)%\7-zip\7z.exe


    if "%sevenzip%"=="" if exist "%ProgramFiles%\7-zip\7z.exe" set 

    sevenzip=%ProgramFiles%\7-zip\7z.exe


    if "%sevenzip%"=="" echo 7-zip not found&pause&exit

    for /D %%O in (*) do (

        for /R %%I in ("%%O\*") do (
            "%sevenzip%" a -mx "%%~na.zip" "%%a"

            ::        rd /s /q "%%I"  **Because I do not want to delete anything by now.

        )
    )

再次谢谢你。

Alex。

推荐答案

如果文件夹结构有些复杂,则最好使用 dir

If you have somewhat complex folder structure then you probably better use plain list from dir:

  dir /a:-d /s /b /o

只需在中将其输出用于

for /f %%f in ('dir /a:-d /s /b /o') do (
  echo %%f <-- %%f is a full path to a file, do something with it
)

Btw,7zip有一个有用的选项 -sdel 在成功创建存档后删除源文件。

Btw, 7zip has useful option -sdel to remove the source file when archive has been created successfully.

这篇关于分别压缩子文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆