I wish to create a batch file that compares 3 different files and decides the action upon which file is the oldest. Very simple, but not for me. I'm not expecting someone to write the file for me, but maybe someone can point me in a direction as for which commands to use?! What I want to do is the following:
if "file1" is older than "file2" or "file3" goto backup1 else goto 2
:2
if "file2" is older than "file3" goto backup2 else goto backup3
:backup1
"execute program1":backup2
"execute program2":backup3
"execute program3"
are the files in different directories?
do they all have the same name?
@echo off for /F %%f in ('dir file1 file2 file3 /B /O-D') do (
echo set oldestfile=%%f> c:\temp.cmd
)call c:\temp.cmd
del c:\temp.cmdecho oldestfile=%oldestfile%
Hi nbrane and tvc Thank you for responding. I'm sorry I haven't responded before, but I've been busy trying to figure it out myself, and so I began (and is at lesson 12 in this batch file course: http://www.allenware.com/icsw/icswi...
Anyways. The files are in different directories and they have the same name. So with the knowledge I got now, I don't think that nbrane's script will do the job. At least not without some modification.
Suggestions are still of interest, since I still can't figure it out myself.
Thanks.
In that case, I suggest you pick up VBScript.
I still haven't figured out what the task is.
=====================================
Helping others achieve escape felicityM2
i would use xcopy /d to determine the date to avoid all the date-confusion. First, collect the filenames:
set fname=test
set c=0
for /f "tokens=*" %%a in ('dir /b /a-d %fname%') do (
set /a c+=1
set x!c!=%%a
)
:: now do the testing (only set up for 3)
set a=1
set b=2
call :test
if %z% equ 1 goto :13
set a=2
set b=3
call :test
if %z% equ 1 goto :TWO
goto :THREE
:13
set a=1
set b=3
call :test
if %z%=1 goto :ONE
goto :THREE:test
xcopy /d /l /y !x%a%! !x%b%! | find "1 File" 2>nul
set z=%errorlevel%:ONE
echo %x1% is oldest
goto :eof
:two
echo %x2% is oldest
goto :eof
:three
echo %x3% is oldest
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |