Board logo

标题: [文本处理] 【已解决】如何提高BAT运行效率 [打印本页]

作者: 思想之翼    时间: 2014-8-25 19:46     标题: 【已解决】如何提高BAT运行效率

本帖最后由 思想之翼 于 2014-8-25 23:53 编辑

命名为“文本”的文件夹内有12个子文件夹,分别命名为 文本1 文本2 ...文本12
每个子文件夹内又有210个子文件夹,分别命名为 001  002 ...210
001  002 ...210文件夹内的 lishi文件夹里有若干txt文本
欲删除lishi里的*+1.txt文本,写了如下代码,共2520行,效率不高,如何优化?
  1. del /s /Q d:\文本\文本1\001\lishi\*+1.txt
  2. del /s /Q d:\文本\文本1\002\lishi\*+1.txt
  3. ...
  4. del /s /Q d:\文本\文本1\210\lishi\*+1.txt
  5. del /s /Q d:\文本\文本2\001\lishi\*+1.txt
  6. del /s /Q d:\文本\文本2\002\lishi\*+1.txt
  7. ...
  8. del /s /Q d:\文本\文本2\210\lishi\*+1.txt
  9. ..........
  10. del /s /Q d:\文本\文本12\001\lishi\*+1.txt
  11. del /s /Q d:\文本\文本12\002\lishi\*+1.txt
  12. ...
  13. del /s /Q d:\文本\文本12\210\lishi\*+1.txt
复制代码

作者: apang    时间: 2014-8-25 20:32

  1. @echo off & setlocal enabledelayedexpansion
  2. for /l %%a in (1001 1 1210) do (
  3.     set "a=%%a"
  4.     for /l %%b in (1 1 12) do (
  5.         del /s /Q d:\文本\文本%%b\!a:~1!\lishi\*+1.txt
  6.     )
  7. )
  8. pause
复制代码

作者: CrLf    时间: 2014-8-26 00:21

本帖最后由 CrLf 于 2014-8-26 00:33 编辑

如果只有最深层的文件夹有 *+1.txt,那可以用暴力的办法:
  1. del /s "d:\文本\*+1.txt"
复制代码





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