我有一个包含子文件夹的文件夹,其中包含名为"Images“的文件夹。我想用7zip压缩所有这些图像文件夹,并将其存储为7s archieve到每个原始文件夹旁边。到目前为止,我写了一个.bat,看起来还不错……但令人惊讶的是,所有创建的归档文件都是空的。有谁能告诉我为什么和如何解决这个问题吗?.bat在包含所有子文件夹的顶层文件夹中打开。
@Echo off
call:myCompressFunction
goto :eof
:myCompressFunction
FOR /D %%G IN (*) DO (
IF "%%G" == "Images" (
"C:\Program Files\7-Zip\7z.exe" ^
a ^
"%%G.7z" ^
"%%G\" ^
-m0=BZip2 ^
-mx=9)
cd %%G\
call:myCompressFunction
cd..
)
exit /b当我将一个文件夹的代码粘贴到我打开的cmd中时,它可以正常工作:
for /d %G in (*) do "C:\Program Files\7-Zip\7z.exe" a "%G.7z" "%G\" -m0=BZip2 -mx=9发布于 2017-04-06 23:10:42
好了,我找到故障了。%%G.7s和%%G\周围不应有标记
以下是添加了一些注释的.bat文件的完整代码:
REM Compresses all folders and subfolders in the folder it is opened but
REM The if-function restricts the folders to be compresses to those named in the if-condition
REM 7z-files are stored aside the original folder
@Echo off
call:myCompressFunction
goto :eof
REM function executed in all subfolders
:myCompressFunction
FOR /D %%G IN (*) DO (
REM compresses all folders named Images
IF "%%G" == "Images" (
"C:\Program Files\7-Zip\7z.exe" ^
a ^
%%G.7z ^
%%G\ ^
-m0=BZip2 ^
-mx=9)
cd %%G\
call:myCompressFunction
cd..
)
exit /bhttps://stackoverflow.com/questions/43258655
复制相似问题