1

I have the input path as C:\Student\Temp in the Temp folder, there will be many other folders. I want to get the latest folder name order by descending.

2
  • What do you mean by latest folder name - latest folder by creation or by usage ? Commented Jul 23, 2015 at 17:33
  • by folder name, all folders names are with name as " created time" Commented Jul 23, 2015 at 17:36

1 Answer 1

2
@echo off

for /f "tokens=* delims=" %%# in ('dir /b /a:d /o:d /t:c "C:\Student\Temp"') do set "latest=%%~nx#"
Sign up to request clarification or add additional context in comments.

3 Comments

You should add the extension format (set "latest=%%~nx#"), for the case that some folder has no name and only extension.
How to print the folder name from the result, to verify the batch is working
@Gani echo %latest%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.