[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]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

本帖最后由 aloha20200628 于 2024-9-1 13:17 编辑


第一问》findstr 加 /i 参数即可
  1. for /f "delims=" %%i in ('dir /b /s /a-d^|findstr /i "ar-sa"') do del /a /f /q "%%i"
复制代码
第二问》可将所有搜索字段 "a..." 至 "z..." 逐行复制到以下代码第2至第7行之间即可
  1. @echo off
  2. for %%c in (
  3.    "af-ZA"
  4.    "am-ET"
  5.     .....
  6.    "zh-TW"  
  7. ) do (for /f "delims=" %%i in ('dir /b /s /a-d^|findstr /i %%c') do del /a /f /q "%%i")
  8. pause&exit/b
复制代码

TOP

回复 2# aloha20200628
  1. @echo off
  2. for %%c in (
  3.    "af-ZA"
  4.    "am-ET"
  5.     .......
  6.    "zh-TW"  
  7. ) do (for /f "delims=" %%i in ('dir /b /s /a-d^|findstr /i %%c') do del /a /f /q "%%i")
  8. pause&exit/b
复制代码
要是 想把文件夹和文件都删除 是不是  只要去掉  /a-d

TOP

本帖最后由 aloha20200628 于 2024-9-1 13:27 编辑

回复 3# lovekix

删除文件用 del
删除目录用 rd
但有可能目录中包含与目录名搜索词不匹配的文件...
可在命令行分别用 del /? 和 rd /? 查看用法详解

TOP

回复 4# aloha20200628


    对对对   忘记了

这样对吗
  1. ) do (for /f "delims=" %%i in ('dir /b /s /ad^|findstr /i %%c') do rd /s/q "%%i")
  2. pause&exit/b
复制代码

TOP

本帖最后由 lovekix 于 2024-9-1 14:00 编辑

-------------

TOP

本帖最后由 aloha20200628 于 2024-9-1 14:06 编辑

回复 5# lovekix

可以。但其实 dir /b /s /a-d^|findstr /i "ar-sa" 还可以简化如下
       dir /b /s /a-d "*ar-sa*"
       dir /b /s /ad "*ar-sa*"
dir 不区分路径文件名大小写
用 dir /b/s ... 搜索匹配的结果是全路径文件名/目录名,可直接交付给 del/rd 操作,没必要再用 pushd ...

TOP

回复  lovekix

可以。但其实 dir /b /s /a-d^|findstr /i "ar-sa" 还可以简化如下
       dir /b /s / ...
aloha20200628 发表于 2024-9-1 13:54



    可以 吧ar-sa .....
写到一个 config.ini 里面 吗?

TOP

本帖最后由 aloha20200628 于 2024-9-1 16:13 编辑

回复 8# lovekix
如果 config.ini 文件每行内容如下:
af-ZA
...
zh-TW
可用以下代码
  1. @echo off & for /f "delims=" %%c in (config.ini) do (
  2.     for /f "delims=" %%i in ('dir /b /s /a-d "*%%c*" ') do del /a /f /q "%%i"
  3. )
  4. pause&exit/b
复制代码

TOP

本帖最后由 WHY 于 2024-9-1 17:36 编辑

windows 文件系统本身是不区分大小写的,dir 如果区分大小写就没意义了。

del 删除文件时,支持搜索子目录,支持通配符。
dir + findstr + del ,或者 dir + del 都是多此一举。
  1. del /s /a /f /q *af-ZA* *am-ET* *ar-SA* *bg-BG* *az-Latn-AZ*
复制代码
可以添加很多关键字,只要命令总长度不超过 8192 字符就行。

rd 删除目录需要 dir 辅助,因为子目录必须 sort /r

TOP

楼主可以添加点文字描述,不要以代码代表...

楼主代码中的 ar-SA 指的是文件还是文件夹?
bat小白,请多指教!谢谢!

TOP

回复 11# 77七


    又有文件夹  又有文件

TOP

回复 10# WHY
  1. ar-sa
  2. af-za
  3. am-et
  4. as-in
  5. az-latn-az
  6. arab~und-arab
  7. bg-bg
  8. bn-in
  9. bs-latn-ba
  10. ba-ru
  11. be-by
  12. bn-bd
  13. beng~und-beng
复制代码
我把 这些放在了  config.ini文件里面了
怎么才能快速的删除 包含 这些的文件夹和文件

TOP

本帖最后由 aloha20200628 于 2024-9-1 20:10 编辑

回复 8# lovekix

稳妥起见(避免搜索文件与搜索目录仅为部分交集而有漏删),先遍历各目录删除所有包含指定搜索词的文件,再遍历各目录删除所有包含同一搜索词的目录及其子目录,利用 rd 命令的容错性,任其自行处理即可...
  1. @echo off & for /f "delims=" %%c in (config.ini) do (
  2. for /f "delims=" %%F in ('dir /b/s/a-d "*%%c*" ') do del /f/q "%%F"
  3. for /f "delims=" %%D in ('dir /b/s/ad "*%%c*" ') do rd /s/q "%%D"
  4. ) 2>nul
  5. pause&exit/b
复制代码

TOP

多个关键词同时遍历,显然更快更科学;先删目录,再删文件,显然更快更科学。
  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
复制代码
1

评分人数

TOP

返回列表