Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .