How to find the last directory created in batch

dan*_*110 5 windows directory datetime cmd batch-file

This is my first question and I'm not very experienced using batch files so hope someone can help.

I want to find the last directory created using a batch file and have tried:

FOR /f "tokens=*" %%A in ('dir "%latestdirectory%" /AD-h /B /o-d') do (set recent=%%A)
Run Code Online (Sandbox Code Playgroud)

but this result keeps returning the oldest directory not the most recent one.

Still trying to pick this up in batch.

End*_*oro 6

FOR /f "delims=" %%A in ('dir "%latestdirectory%" /AD-h /B /od') do (set recent=%%A)
Run Code Online (Sandbox Code Playgroud)

如需帮助dir /? ,请在命令行输入 .