Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.