简体   繁体   中英

windows batch dir command get last modified directory starting with string

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?

for /f "delims=" %%a in ('dir /b /ad-h /od "Anoth*"') do set "latestDir=%%~a"
echo(%latestDir%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM