[英]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.