[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] [已解决]批处理怎么指定数字删除多个子目录下的文件?

本帖最后由 wyx567 于 2015-9-25 10:25 编辑

多个子目录下有1.swf到200.swf,1.png到200.png,
怎么指定删除,比如,删除21.swf,21.png后面的文件,只保留1-20.swf,1-20.png呢
文件夹内还有别的如txt,PDF文件,这些不动


请大家看看,谢谢!
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

本帖最后由 flyinnet9 于 2015-9-23 09:38 编辑
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set /p n=请输入要删除的文件开始序号并回车(例如21):
  4. for /f "delims=" %%a in ('dir /a-d /s /b *.swf *.png') do (
  5.   set f=%%~na
  6.   for /f "delims=1234567890" %%i in ("!f!") do if not "%%i"=="" set f=1
  7.   if !f! geq %n% del /q "%%a"
  8. )
复制代码
1

评分人数

TOP

回复 2# flyinnet9

运行后子文件夹内文件全部都删除了
试过几个序号都是这样~

TOP

哦哦我明白了
全部删除是因为有的子文件夹下没有png文件

这里能不能设置下,有的文件夹内没有png文件怎么处理呢?

TOP

回复 3# wyx567


    测试没问题

完全按照本程序的话,只会删除21以上的.swf .png文件
即1-20保留,21-???删除

TOP

有的文件夹内没有PNG文件的,
这样测试就会该文件夹内所有内容全部删除

有的文件夹内没有png文件的怎么处理呢?

谢谢

TOP

子文件夹内有的是swf,png文件都有,有的只有swf文件

这样用您的代码测试,swf,png文件都有的子文件夹处理成功,只有swf文件的文件夹内所有文件都被删除了

TOP

回复 7# wyx567


    完全没有这回事,根本就不会搜索其他后缀的文件

TOP

回复 8# flyinnet9


链接: http://pan.baidu.com/s/1jGgvo2a 密码: v9b4

我把测试文件打包了您看看,应该没操作错误

TOP

回复 9# wyx567

测试结果如下,完全没问题啊
  1. D:\Script\TEST\003>123
  2. 请输入要删除的文件开始序号并回车(例如21):21
  3. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf"
  4. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\21.swf"
  5. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\22.swf"
  6. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\23.swf"
  7. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\24.swf"
  8. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\25.swf"
  9. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\26.swf"
  10. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\27.swf"
  11. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\28.swf"
  12. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\29.swf"
  13. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\30.swf"
  14. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\31.swf"
  15. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\32.swf"
  16. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\33.swf"
  17. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\34.swf"
  18. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\35.swf"
  19. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\36.swf"
  20. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\37.swf"
  21. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\38.swf"
  22. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\39.swf"
  23. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\40.swf"
  24. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\41.swf"
  25. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\42.swf"
  26. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\43.swf"
  27. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\44.swf"
  28. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\45.swf"
  29. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\46.swf"
  30. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\47.swf"
  31. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\48.swf"
  32. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\49.swf"
  33. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\50.swf"
  34. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\51.swf"
  35. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\52.swf"
  36. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\53.swf"
  37. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\54.swf"
  38. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\55.swf"
  39. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\56.swf"
  40. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\57.swf"
  41. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\58.swf"
  42. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\59.swf"
  43. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\60.swf"
  44. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\61.swf"
  45. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\62.swf"
  46. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\63.swf"
  47. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\64.swf"
  48. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\65.swf"
  49. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\66.swf"
  50. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\67.swf"
  51. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\68.swf"
  52. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\69.swf"
  53. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\70.swf"
  54. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\71.swf"
  55. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\72.swf"
  56. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\73.swf"
  57. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\74.swf"
  58. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\75.swf"
  59. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\76.swf"
  60. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\77.swf"
  61. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\78.swf"
  62. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\79.swf"
  63. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\80.swf"
  64. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\81.swf"
  65. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\82.swf"
  66. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\83.swf"
  67. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\84.swf"
  68. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\85.swf"
  69. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\86.swf"
  70. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\87.swf"
  71. del /q "D:\Script\TEST\003\0cb4l5g79sp0yyr5.swf\88.swf"
  72. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\21.swf"
  73. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\22.swf"
  74. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\23.swf"
  75. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\24.swf"
  76. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\25.swf"
  77. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\26.swf"
  78. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\27.swf"
  79. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\28.swf"
  80. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\29.swf"
  81. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\30.swf"
  82. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\31.swf"
  83. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\32.swf"
  84. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\33.swf"
  85. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\34.swf"
  86. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\35.swf"
  87. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\36.swf"
  88. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\37.swf"
  89. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\38.swf"
  90. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\39.swf"
  91. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\40.swf"
  92. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\41.swf"
  93. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\42.swf"
  94. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\43.swf"
  95. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\44.swf"
  96. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\45.swf"
  97. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\46.swf"
  98. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\47.swf"
  99. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\48.swf"
  100. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\49.swf"
  101. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\50.swf"
  102. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\51.swf"
  103. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\52.swf"
  104. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\53.swf"
  105. del /q "D:\Script\TEST\003\f6m4gcvlg9s39fuh.swf\54.swf"
复制代码

TOP

回复 10# flyinnet9

你好, 文件夹内同时有swf和png文件的文件夹'0cb4l5g79sp0yyr5.swf'操作正常,
但是你看另外一个只有swf文件的'f6m4gcvlg9s39fuh.swf'文件夹,里面都清空了~

TOP

  1. @echo off&color 0e
  2. set/p file_path=输入路径:
  3. set/p number=输入数字[大于或等于]的进行删除:
  4. for /f "delims=" %%i in ('dir/a-d/s/b/l/on "%file_path%\*.*"') do (
  5. if /i not "%%~ni"=="%%~nxi" (if /i "%%~xi"==".png" if %%~ni geq %number% del/f/q "%%i"
  6.   if /i "%%~xi"==".swf" if /i "%%~xi"==".png" if %%~ni geq %number% del/f/q "%%i"
  7. )
  8. )
  9. pause
复制代码

TOP

本帖最后由 flyinnet9 于 2015-9-23 09:46 编辑

回复 11# wyx567


    靠!!!!!!!!!!
    我看了半天,文件夹有.swf后缀,已改 回看2楼

TOP

本帖最后由 wyx567 于 2015-9-25 10:23 编辑

回复 13# flyinnet9

是的大哥,麻烦你了,我来看看!!!


OK,测试完美,谢谢!!!

TOP

回复 12# /zhqsystem/zhq

这位哥们也谢谢你!
但是测试只能删除png文件,里面的swf没有变动~

TOP

返回列表