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

[文本处理] 【已解决】批处理命令 dir 区分大小写吗?

本帖最后由 lovekix 于 2024-9-3 10:29 编辑
  1. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ar-SA"') do del /a /f /q "%%i"
复制代码
  1. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ar-sa"') do del /a /f /q "%%i"
复制代码
第一问: 有必要  写两行吗?



第二问:如果 要是很多  怎么才能 减少运行时间
  1. pushd C:
  2. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "af-ZA"') do del /a /f /q "%%i"
  3. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "am-ET"') do del /a /f /q "%%i"
  4. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ar-SA"') do del /a /f /q "%%i"
  5. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "as-IN"') do del /a /f /q "%%i"
  6. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "az-Latn-AZ"') do del /a /f /q "%%i"
  7. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "bg-BG"') do del /a /f /q "%%i"
  8. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "bn-IN"') do del /a /f /q "%%i"
  9. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "bs-Latn-BA"') do del /a /f /q "%%i"
  10. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ca-Es-VALENCIA"') do del /a /f /q "%%i"
  11. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ca-ES"') do del /a /f /q "%%i"
  12. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "cs-CZ"') do del /a /f /q "%%i"
  13. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "cy-GB"') do del /a /f /q "%%i"
  14. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "da-DK"') do del /a /f /q "%%i"
  15. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "de-DE"') do del /a /f /q "%%i"
  16. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "el-GR"') do del /a /f /q "%%i"
  17. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "en-GB"') do del /a /f /q "%%i"
  18. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "en-AU"') do del /a /f /q "%%i"
  19. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "en-CA"') do del /a /f /q "%%i"
  20. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "en-IN"') do del /a /f /q "%%i"
  21. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "en-GB"') do del /a /f /q "%%i"
  22. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "es-ES"') do del /a /f /q "%%i"
  23. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "es-MX"') do del /a /f /q "%%i"
  24. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "et-EE"') do del /a /f /q "%%i"
  25. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "eu-ES"') do del /a /f /q "%%i"
  26. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "fa-IR"') do del /a /f /q "%%i"
  27. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "fi-FI"') do del /a /f /q "%%i"
  28. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "fil-PH"') do del /a /f /q "%%i"
  29. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "fr-CA"') do del /a /f /q "%%i"
  30. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "fr-FR"') do del /a /f /q "%%i"
  31. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ga-IE"') do del /a /f /q "%%i"
  32. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "gd-gb"') do del /a /f /q "%%i"
  33. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "gl-ES"') do del /a /f /q "%%i"
  34. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "gu-IN"') do del /a /f /q "%%i"
  35. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "he-IL"') do del /a /f /q "%%i"
  36. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "hi-IN"') do del /a /f /q "%%i"
  37. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "hr-HR"') do del /a /f /q "%%i"
  38. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "hu-HU"') do del /a /f /q "%%i"
  39. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "hy-AM"') do del /a /f /q "%%i"
  40. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "id-ID"') do del /a /f /q "%%i"
  41. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "is-IS"') do del /a /f /q "%%i"
  42. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "it-IT"') do del /a /f /q "%%i"
  43. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ja-JP"') do del /a /f /q "%%i"
  44. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ka-GE"') do del /a /f /q "%%i"
  45. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "kk-KZ"') do del /a /f /q "%%i"
  46. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "km-KH"') do del /a /f /q "%%i"
  47. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "kn-IN"') do del /a /f /q "%%i"
  48. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ko-KR"') do del /a /f /q "%%i"
  49. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "kok-IN"') do del /a /f /q "%%i"
  50. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "lb-LU"') do del /a /f /q "%%i"
  51. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "lo-LA"') do del /a /f /q "%%i"
  52. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "lt-LT"') do del /a /f /q "%%i"
  53. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "lv-LV"') do del /a /f /q "%%i"
  54. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "mi-NZ"') do del /a /f /q "%%i"
  55. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "mk-MK"') do del /a /f /q "%%i"
  56. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ml-IN"') do del /a /f /q "%%i"
  57. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "mr-IN"') do del /a /f /q "%%i"
  58. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ms-MY"') do del /a /f /q "%%i"
  59. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "mt-MT"') do del /a /f /q "%%i"
  60. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "nb-NO"') do del /a /f /q "%%i"
  61. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ne-NP"') do del /a /f /q "%%i"
  62. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "nl-NL"') do del /a /f /q "%%i"
  63. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "nn-NO"') do del /a /f /q "%%i"
  64. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "or-IN"') do del /a /f /q "%%i"
  65. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "pa-IN"') do del /a /f /q "%%i"
  66. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "pl-PL"') do del /a /f /q "%%i"
  67. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "pt-BR"') do del /a /f /q "%%i"
  68. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "pt-PT"') do del /a /f /q "%%i"
  69. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "quz-PE"') do del /a /f /q "%%i"
  70. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ro-RO"') do del /a /f /q "%%i"
  71. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ru-RU"') do del /a /f /q "%%i"
  72. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sk-SK"') do del /a /f /q "%%i"
  73. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sl-SI"') do del /a /f /q "%%i"
  74. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sq-AL"') do del /a /f /q "%%i"
  75. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sr-Cyrl-BA"') do del /a /f /q "%%i"
  76. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sr-Cyrl-RS"') do del /a /f /q "%%i"
  77. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sr-Latn-RS"') do del /a /f /q "%%i"
  78. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "sv-SE"') do del /a /f /q "%%i"
  79. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ta-IN"') do del /a /f /q "%%i"
  80. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "te-IN"') do del /a /f /q "%%i"
  81. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "th-TH"') do del /a /f /q "%%i"
  82. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "tr-TR"') do del /a /f /q "%%i"
  83. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "tt-RU"') do del /a /f /q "%%i"
  84. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ug-CN"') do del /a /f /q "%%i"
  85. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "uk-UA"') do del /a /f /q "%%i"
  86. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "ur-PK"') do del /a /f /q "%%i"
  87. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "uz-Latn-UZ"') do del /a /f /q "%%i"
  88. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "vi-VN"') do del /a /f /q "%%i"
  89. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr "zh-TW"') do del /a /f /q "%%i"
  90. 删除了小写的
  91. PAUSE
复制代码
1

评分人数

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

本帖最后由 77七 于 2024-9-3 14:52 编辑

回复 27# lovekix


   
这样试下,如果还是不行,检查 list_all.txt 及 list_del.txt 是否包含未删除的文件。
  1. @echo off
  2. cd /d "%~dp0"
  3. set keys=config.ini
  4. (for /f "useback" %%a in ("%keys%") do (
  5. echo %%a
  6. )) > "list_keys.txt"
  7. dir /a /b /s "c:\" "c:\windows" > "list_all.txt"
  8. findstr /ig:"list_keys.txt" "list_all.txt" > "list_del.txt"
  9. for /f "useback delims=" %%i in ("list_del.txt") do (
  10. if exist "%%i\" (
  11. rd /s /q "%%i"
  12. ) else if exist "%%i" (
  13. del /a /f "%%i"
  14. )
  15. )
  16. rem del list_*.txt
  17. pause
复制代码
1

评分人数

bat小白,请多指教!谢谢!

TOP

本帖最后由 aloha20200628 于 2024-9-3 12:34 编辑

回复 23# lovekix

分两步也许可提速》先 rd 完成 ‘大量的集团’ 清理,其后 del 再完成 ‘少量剩余的单兵’ 清理,二者没有重复操作,订正代码如下...
  1. @echo off
  2. for /f "delims=" %%c in (config.ini) do (for /f "delims=" %%a in ('dir /b/s "*%%c*" ') do rd /s/q "%%a") 2>nul
  3. for /f "delims=" %%c in (config.ini) do (for /f "delims=" %%a in ('dir /b/s "*%%c*" ') do del /f/q "%%a") 2>nul
  4. pause&exit/b
复制代码

TOP

回复 26# 77七


    没有删除  其他目录
没有报错

TOP

回复 25# lovekix


   其它目录下的文件删除了吗?有没有报错信息?
bat小白,请多指教!谢谢!

TOP

回复 24# 77七


    效果一样  还是只删除了 文件夹

TOP

回复 22# lovekix


   看了你的反馈,未删除的文件 都位于 "C:\Windows" 下
  1. @echo off
  2. cd /d "%~dp0"
  3. for /f "delims=" %%i in ('dir /a /b /s "c:\" "C:\Windows\" ^|findstr /ig:"config.ini"') do (
  4. if exist "%%i\" (
  5. echo rd /s /q "%%i"
  6. ) else if exist "%%i" (
  7. echo del /a /f "%%i"
  8. )
  9. )
  10. pause
复制代码
bat小白,请多指教!谢谢!

TOP

回复 18# aloha20200628


    用时3分40秒

TOP

本帖最后由 lovekix 于 2024-9-3 07:00 编辑

回复 17# 77七


    10秒就搞定了

但是删的不全  文件夹删除了  文件还保留

TOP

本帖最后由 lovekix 于 2024-9-3 10:30 编辑

回复 15# WHY


   

PE不支持  sort


我提取了一个 sort   都删除完了    很完美
https://wwrj.lanzouw.com/iD7v4290xbpg



用时1分25秒
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "tokens=*" %%i in (config.ini) do (
  4.     set key=!key! "*%%i*"
  5. )
  6. endlocal & set key=%key%
  7. for /f "delims=" %%i in ('dir /b /ad /s %key% ^| sort /r') do (
  8.     rd /s /q "%%i"
  9. )
  10. del /s /a /f /q %key%
  11. pause
复制代码

TOP

生动!!!!!!!

TOP

有10个框,每个筐装10个球,需要找出并扔掉压破的、压瘪的球和框,两种办法:
办法1:
1.从第1个框(目录)开始,找出框中压破了的球(文件),扔掉;直到10个框的球都找遍;
2.重复第1步,找出框中压瘪了的球(文件),扔掉;直到10个框的球都找遍;
3.从第1个框(目录)开始,找到压破了的框,扔掉;直到10个框都找遍;
4.重复第3步,找出压瘪了的框,扔掉;直到所有框都找遍。

办法2:
1.从第1个框(目录)开始,找到破框或瘪框,扔掉,直到10个框都找遍;
2.从第1个框(目录)开始,找到破球或瘪球(文件),扔掉,直到所有球都找遍。

只要有正常逻辑思维的人,一般会选择办法2;
也有人偏不信邪,非办法1不选,其思维、逻辑总是超乎常人,bat新手老手一个比一个懵逼;
我一般不愿把人往坏处想,就当这是为了彰显其独特的个性与魅力吧。

TOP

本帖最后由 aloha20200628 于 2024-9-2 09:19 编辑


充分利用 rd 和 del 的容错性,还可进一步简化操作及检测步骤...
  1. @echo off & for /f "delims=" %%c in (config.ini) do (for /f "delims=" %%a in ('dir /b/s "*%%c*" ') do (
  2.      rd /s/q "%%a"
  3.      del /f/q "%%a"
  4. )) 2>nul
  5. pause&exit/b
复制代码

TOP

  1. @echo off
  2. cd /d c:\
  3. for /f "delims=" %%i in ('dir /a /b /s ^|findstr /ig:"config.ini"') do (
  4. if exist "%%i\" (
  5. echo rd /s /q "%%i"
  6. ) else if exist "%%i" (
  7. echo del /a /f "%%i"
  8. )
  9. )
  10. pause
复制代码
bat小白,请多指教!谢谢!

TOP

回复 12# lovekix

如果被删除的目标目录包含所有被删除的目标文件,则14楼代码可删除第2行;若非也,则可调换2,3行序,确实可提高整体删除效率...

TOP

返回列表