简体   繁体   English

如何使用Windows批处理文件查找特定目录?

[英]How can I find specific directories using Windows batch file?

I have a batch file that finds last modified directory in the path 我有一个批处理文件,该文件在路径中找到最后修改的目录

for /f "delims= %%x in (' dir / ad /od /b "C:\Path") do set newest=%%x

I need to modify this script to only look for certain folders and find a last modified one. 我需要修改此脚本,以便仅查找某些文件夹并找到最后修改的文件夹。 For example, if the path contains 4 directories(Red, Blue, Green, Yellow), I want to let command to only look for 2 directories(Blue, Green), and find the latest modified one. 例如,如果路径包含4个目录(红色,蓝色,绿色,黄色),我想让命令仅查找2个目录(蓝色,绿色),并找到最新修改的目录。

for /f "delims=" %%x in (
  'dir / ad /od /b "C:\Path" ^| Findstr /i "Blue Green" '
    ) do set newest=%%x

Will filter in an or fashion all lines containing Blue or Green in any position in the line. 将以or方式过滤行中任何位置包含蓝色或绿色的所有行。

With directory names like that you'll even get away without the findstr: 使用这样的目录名,甚至不需要findstr就可以逃脱:

@ECHO OFF
FOR /F "DELIMS=" %%A IN ('DIR/B/AD-L/OD "C:\PATH\B?UE" "C:\PATH\GR?EN"') DO (
    SET "NEWEST=%%A"
SET NEWEST
PAUSE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Windows批处理文件的递归副本中排除特定目录? - How do I exclude specific directories from a recursive copy in a Windows batch file? Windows Batch脚本可查找具有特定扩展名的文件,并将其目录写入文本文件 - Windows Batch script to find files with specific extensions, write their directories to a text file 如何将文件批量复制到多个子目录? - how can I batch copy a file into multiple sub-directories? 如何使用批处理文件捕获Windows硬件配置? - How can I capture Windows hardware configuration using a batch file? 如何使用Windows批处理命令一次在c,d,e驱动器的所有目录中搜索文件 - how to search file(s) in all the directories of c,d,e drives at a time using windows batch commands 如何使用批处理文件在 Windows 10 中删除具有特定名称的文件? - How to delete files with specific names in windows 10 using batch file? 如何使用Windows批处理读取txt文件中的特定字符串? - How to read specific string in txt file by using windows batch? 如何使用Windows批处理文件在其中找到目录并将其存储到变量中? - How do I find a directory in and store it into a variable, using a Windows batch file? 如何使用Windows批处理脚本在“,”中查找和替换文本文件中的“=”? - How to find and replace “=” in a text file with “,” using windows batch script? 如何查找使用批处理文件安装Windows的位置 - How to find where windows is installed using batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM