Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a folder which have some log files. I want to open the latest log file through command prompt i.e. the file having the latest modified date/time. I am able to go to the folder through command prompt but how can I access the last modified one?

share|improve this question

The DIR command can sort by last modified date. FOR /F can process the result. The variable will be set to the last file listed.

for /f "eol=: delims=" %F in ('dir /b /od *.log') do @set "newest=%F"
notepad "%newest%"

Double up the percents if used within a batch script: %F becomes %%F.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.