windows batch dir command get last modified direct

2019-07-28 06:31发布

I want to get the last modified directory starting with a string stringEx... in a windows batch file.

For example: I have a folder containing sub-directories like this :

- Directory
  -Subdirectory1
  -Subdirectory2
  -Anothersubdirectory
....

I tried with this but it doesn't work:

@echo off
Setlocal EnableDelayedExpansion
Set foundedFolder

FOR /F %%i IN ('dir C:\Directory | subtsr "Anoth*" /b /ad-h /od') DO (SET a=%%i)

%foundedFolder%=%a%

Any ideas?

1条回答
等我变得足够好
2楼-- · 2019-07-28 07:00
for /f "delims=" %%a in ('dir /b /ad-h /od "Anoth*"') do set "latestDir=%%~a"
echo(%latestDir%
查看更多
登录 后发表回答