Using FOR or FORFILES batch command to individually archive specific files

人走茶凉 提交于 2019-12-02 11:53:01
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
FOR /f "delims=" %%a IN (
  'dir /s/b /a-d "%sourcedir%\*.iso" '
  ) DO (
  ECHO(7z a -t7z "%%~fa.7z" "%%~fa" -mx9 -mmt 
)
GOTO :EOF

You would need to change the setting of sourcedir to suit your circumstances.

The required 7z commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(7z to 7z to actually archive the files.

Note that the redirection-to-log is missing. This is done to allow the proposed actions to be displayed to the screen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!