Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 720
user3019331 Avatar asked May 13 '26 00:05

user3019331


1 Answers

for /f "delims=" %%a in ('dir /b /ad-h /od "Anoth*"') do set "latestDir=%%~a"
echo(%latestDir%
like image 60
Endoro Avatar answered May 14 '26 17:05

Endoro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!