0

I have a script that I'm working on that I'm pretty stuck on... It may be just a syntax error but I'm not sure.

The script checks how old each file is that is hardcoded in the script (This script is a subscript that is being generated by another). The checkage2.bat script outputs an %AGE% variable if file is over 20 minutes old the AGE=1 otherwise AGE=0

SET FILEPATH="C:\PathToFile\Filename1.slf"  
CALL C:\PathToScript\checkage2.bat %FILEPATH%  
IF %AGE% EQU 1 OUTPUT=%OUTPUT% %FILEPATH%

SET FILEPATH="C:\PathToFile\Filename2.slf"  
CALL C:\PathToScript\checkage2.bat %FILEPATH%  
IF %AGE% EQU 1 OUTPUT=%OUTPUT% %FILEPATH%

SET FILEPATH="C:\PathToFile\Filename3.slf"  
CALL C:\PathToScript\checkage2.bat %FILEPATH%  
IF %AGE% EQU 1 OUTPUT=%OUTPUT% %FILEPATH%
IF (%OUTPUT%) == () GOTO OK

ECHO CRITICAL: %OUTPUT%
PAUSE

:OK
ECHO OK: All files within 20 minute time range 
PAUSE 

I'm trying to output a full list of all files that are over 20 minutes old but I can't seem to get it right! Any help will be really appreciated, thanks all!

2 Answers 2

1
IF %AGE% EQU 1 OUTPUT=%OUTPUT% %FILEPATH%

Maybe if you were to SET OUTPUT=...

Sign up to request clarification or add additional context in comments.

3 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
@KickButtowski Dingo's kidneys! The response I've made is obvious - but if you really need it to be explicit (this is known as "spoonfeeding") then IF %AGE% EQU 1 OUTPUT=%OUTPUT% %FILEPATH% should be IF %AGE% EQU 1 SET OUTPUT=%OUTPUT% %FILEPATH% throughout because in batch, to set a variable you need to use the set keyword, not simply use the required expression, as MCND posted a whole minute later.
Thanks Magoo, your first answer was more than enough :) thanks for your help
0

The problem seems to be the missing SET commands in variable assignment and the IF condition that will fail when there are spaces between the elements.

SET "OUTPUT="

SET FILEPATH="C:\PathToFile\Filename1.slf"
CALL C:\PathToScript\checkage2.bat %FILEPATH%
IF %AGE% EQU 1 SET OUTPUT=%OUTPUT% %FILEPATH%

SET FILEPATH="C:\PathToFile\Filename2.slf"
CALL C:\PathToScript\checkage2.bat %FILEPATH%
IF %AGE% EQU 1 SET OUTPUT=%OUTPUT% %FILEPATH%

SET FILEPATH="C:\PathToFile\Filename3.slf"
CALL C:\PathToScript\checkage2.bat %FILEPATH%
IF %AGE% EQU 1 SET OUTPUT=%OUTPUT% %FILEPATH% 

IF DEFINED OUTPUT (
    ECHO CRITICAL: %OUTPUT% 
) ELSE (
    ECHO OK: All files within 20 minute time range
)
PAUSE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.