单独压缩子文件夹中的文件
Compress separately files within subfolders
大家好,感谢您的回答,
首先,我试图找到我的问题的答案,但我什么也没找到。
我有一棵文件夹和子文件夹树,我想使用 7zip 分别压缩这些文件夹中的文件。
我从这个网站上获得了这段代码,它可以实现我想要的功能,但它将压缩文件放在主文件夹中:
set extension=.*
for /R %%a in (*%extension%) do "%sevenzip%" a -mx "%%~na.zip" "%%a"
我想知道我是否可以获得每个文件的 zip 文件并将其放在包含源文件的子文件夹中。或者执行上述过程并将每个 zip 文件放入适当的子文件夹中。
我试过双 'For /d' 但我无法得到它:
cd /d %~dp0
rem 7z.exe path
set sevenzip=
if "%sevenzip%"=="" if exist "%ProgramFiles(x86)%-zipz.exe" set
sevenzip=%ProgramFiles(x86)%-zipz.exe
if "%sevenzip%"=="" if exist "%ProgramFiles%-zipz.exe" set
sevenzip=%ProgramFiles%-zipz.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.
)
)
再次感谢。
亚历克斯
如果您的文件夹结构有些复杂,那么您最好使用来自 dir
:
的普通列表
dir /a:-d /s /b /o
只需在for
中使用它的输出:
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
)
顺便说一句,7zip 有一个有用的选项 -sdel
可以在成功创建存档后删除源文件。
这是最终代码:
@echo 关闭
cd /d %~dp0
rem 7z.exe 路径
设置 sevenzip=
if "%sevenzip%"=="" 如果存在 "%ProgramFiles(x86)%-zipz.exe" set sevenzip=%ProgramFiles(x86)%-zipz.exe
if "%sevenzip%"=="" 如果存在 "%ProgramFiles%-zipz.exe" set sevenzip=%ProgramFiles%-zipz.exe
if "%sevenzip%"=="" echo 7-zip not found&pause&exit
@echo 搜索...
for /R %%I in (*) do (
"%sevenzip%" a -mx -mmt4 "%%I.7z" -r -x!*.bat "%%I"
)
del "Compressing_files_7zip.bat.7z"*
del *.7z.7z
del *.zip.7z
::::::::::::::::::::::::::用于在 process.Remove 冒号结束后 60' 处设置关机下面一行。
::shutdown.exe/s/t 3600
暂停
感谢大家的支持,尤其是对Frost的支持。
不使用 7zip 的简单版本:
for /f %%f in ('dir /a:-d /s /b /o *.mdb') do (
zip -r -p "%%f.zip" "%%f"
)
大家好,感谢您的回答,
首先,我试图找到我的问题的答案,但我什么也没找到。
我有一棵文件夹和子文件夹树,我想使用 7zip 分别压缩这些文件夹中的文件。
我从这个网站上获得了这段代码,它可以实现我想要的功能,但它将压缩文件放在主文件夹中:
set extension=.*
for /R %%a in (*%extension%) do "%sevenzip%" a -mx "%%~na.zip" "%%a"
我想知道我是否可以获得每个文件的 zip 文件并将其放在包含源文件的子文件夹中。或者执行上述过程并将每个 zip 文件放入适当的子文件夹中。
我试过双 'For /d' 但我无法得到它:
cd /d %~dp0
rem 7z.exe path
set sevenzip=
if "%sevenzip%"=="" if exist "%ProgramFiles(x86)%-zipz.exe" set
sevenzip=%ProgramFiles(x86)%-zipz.exe
if "%sevenzip%"=="" if exist "%ProgramFiles%-zipz.exe" set
sevenzip=%ProgramFiles%-zipz.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.
)
)
再次感谢。
亚历克斯
如果您的文件夹结构有些复杂,那么您最好使用来自 dir
:
dir /a:-d /s /b /o
只需在for
中使用它的输出:
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
)
顺便说一句,7zip 有一个有用的选项 -sdel
可以在成功创建存档后删除源文件。
这是最终代码:
@echo 关闭
cd /d %~dp0
rem 7z.exe 路径
设置 sevenzip=
if "%sevenzip%"=="" 如果存在 "%ProgramFiles(x86)%-zipz.exe" set sevenzip=%ProgramFiles(x86)%-zipz.exe
if "%sevenzip%"=="" 如果存在 "%ProgramFiles%-zipz.exe" set sevenzip=%ProgramFiles%-zipz.exe
if "%sevenzip%"=="" echo 7-zip not found&pause&exit
@echo 搜索...
for /R %%I in (*) do (
"%sevenzip%" a -mx -mmt4 "%%I.7z" -r -x!*.bat "%%I"
)
del "Compressing_files_7zip.bat.7z"*
del *.7z.7z
del *.zip.7z
::::::::::::::::::::::::::用于在 process.Remove 冒号结束后 60' 处设置关机下面一行。 ::shutdown.exe/s/t 3600
暂停
感谢大家的支持,尤其是对Frost的支持。
不使用 7zip 的简单版本:
for /f %%f in ('dir /a:-d /s /b /o *.mdb') do (
zip -r -p "%%f.zip" "%%f"
)