need to only select the time of the oldest file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bowlardo
Posts: 15
Joined: 28 Jun 2012 07:28

need to only select the time of the oldest file

#1 Post by Bowlardo » 23 Aug 2013 03:33

The script is doing everything i want to but it is not picking the first/oldest file from the folder P:\Gensrvnt\workdir\CUSTDCHECK\


echo on
cd..
cd workdir\CUSTDCHECK
IF NOT EXIST P:\Gensrvnt\workdir\CUSTDCHECK\o_100_00000000* GOTO end
REM GET CURRENT TIME(MINUTES only!!)
set mm=%time:~3,-6%
REM get date time of files in folder &REM GET FILE TIME( IN MINUTES!!)
for %%a in (*.*) do set FileDate=%%~ta
set ff=%filedate:~14%
There will be multiple filedata listed but I only want to assign the ff variable to the oldest file time
REM Calculate the difference between minutes of current time minus minutes of the file
set /a cc= %mm%-%ff%
REM if difference is more than 10 then we have an error.
if /i %cc% GTR 10 (echo Error) ELSE echo no error
:end
echo this is the end my friend!

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: need to only select the time of the oldest file

#2 Post by Endoro » 23 Aug 2013 03:46

to grab the oldest "print" the youngest first:

Code: Select all

for /f "delims=" %%a in ('dir /b /o-d /a-d') do SET  "filedate=%%~ta"
echo %filedate%

Post Reply