F
F
Fisab2017-03-28 22:59:13
cmd/bat
Fisab, 2017-03-28 22:59:13

BAT how to get the oldest file in a folder?

You need to look at all the files and find the oldest one, how will it look like for a batch file? I tried many methods, but they do not return the oldest one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmfun, 2017-03-29
@dmfun

@echo off
for /f "delims=" %%F in ('dir /AD /TW /B') do set filename=%%F
goto tests
:tests
@echo on
echo "%filename%"
// loop through output of the dir command with parameters, assign to filename. the last assignment is the result. /AD - no directories /TW - sort by time /B - filenames only
I checked, it seems to work. But I think the logic should be something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question