Board logo

标题: [文件操作] 【已解决】批处理怎样查找/搜索指定名称的文件夹并用WinRAR压缩? [打印本页]

作者: taofan712    时间: 2016-12-29 11:44     标题: 【已解决】批处理怎样查找/搜索指定名称的文件夹并用WinRAR压缩?

本帖最后由 pcl_test 于 2016-12-30 21:13 编辑

首先谢谢各位点击帖子帮忙。
我想用一个批处理,全盘搜索名为picture的文件夹,并用winrar对它们进行压缩,压缩文件就放在picture所在目录。
  1. for %%a in (c: d: e: f: ) do (
  2.       for /f "delims=" %%b in ('dir /ad /b /s %%a\') do (
  3.          if "%%~nxb"=="picture" "C:\Program Files\WinRAR\WinRAR.exe" a  -r - inul -ibck "%%b "
  4.        )
  5. )
  6. pause
复制代码
winrar.exe的开关用不来,老是报错,还有就是-ep1这个参数该不该加上去呢?拜托了。
作者: GNU    时间: 2016-12-30 15:54

  1. for %%a in (c: d: e: f: ) do (
  2.     for /f "delims=" %%b in ('dir /ad /b /s %%a\') do (
  3.         if "%%~nxb"=="picture" (
  4.             "C:\Program Files\WinRAR\WinRAR.exe" a -ep -inul -ibck "%%~dpb%%~nxb.rar" "%%b"
  5.         )
  6.     )
  7. )
  8. pause
复制代码

作者: taofan712    时间: 2016-12-30 18:52

回复 2# GNU


    非常感谢!变量扩充(好像是这么叫吧…)我一直用不来。看你的用法和结果,现在感觉明白多一些了。谢谢。
另外多问一句,昨天qq群里的朋友说我这种方法效率很低,如果可以的话,请问有这个代码怎么改得更高效呢?
作者: codegay    时间: 2016-12-30 19:07

调用everything 进行搜索,秒出。
需要管理员权限。
http://bbs.bathome.net/thread-37744-1-1.html
作者: taofan712    时间: 2016-12-30 19:18

回复 4# codegay


    感谢推荐,第三方工具确实能极大程度提高批处理的能力范围和工作效率,这里具体到我个人使用情况,不准备用外部工具,谢谢啦。
作者: codegay    时间: 2016-12-30 19:41

回复 5# taofan712

是人要用工具为自己服务。不是人给机器服务。
以及winrar 也是第三方工具。




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2