if file exists and is older than x hours
Moderators: Dorian (MJT support), JRL
if file exists and is older than x hours
Hi to all
I know how to use the iffileexists statment but i was wondering if there was a way to check if a file exists and is older than x hours.
e.g
iffileexists>test.text
check if file is older than x hours
if yes do something
else
do something else
endif
I know how to use the iffileexists statment but i was wondering if there was a way to check if a file exists and is older than x hours.
e.g
iffileexists>test.text
check if file is older than x hours
if yes do something
else
do something else
endif
Re: if file exists and is older than x hours
This example tells you how old a file is in seconds.
Code: Select all
Input>vFile,Pick a file
IfFileExists>vFile
FileDate>vFile,vFileDate
MidStr>vFileDate,1,4,yyyy
MidStr>vFileDate,5,2,mm
MidStr>vFileDate,7,2,dd
FileTime>vFile,vFileTime
MidStr>vFileTime,1,2,hh
MidStr>vFileTime,3,2,mn
MidStr>vFileTime,5,2,ss
VBEVal>DateDiff("s","%mm%/%dd%/%yyyy% %hh%:%mn%:%ss%",now()),vSecondsOld
EndIf
MDL>vSecondsOld
Re: if file exists and is older than x hours
hello JRL
i really appreciate your help and assitance with this. i have a patch file that is run at the very end of my exe script. if the patch file is triggered it means the script ran successfully in which the patch file creates a notepad file e.g abc_todays date. i want to check if abc_todays date exist and if its older than 24 hours before the exe script is re-run again.
how would i go about using the sript you provided me with above to do this?
your reply is appreciated.
i really appreciate your help and assitance with this. i have a patch file that is run at the very end of my exe script. if the patch file is triggered it means the script ran successfully in which the patch file creates a notepad file e.g abc_todays date. i want to check if abc_todays date exist and if its older than 24 hours before the exe script is re-run again.
how would i go about using the sript you provided me with above to do this?
your reply is appreciated.
Re: if file exists and is older than x hours
I'd place this first block of code at the beginning of your exe script and run the exe several times per day. Or alternatively and the way I would likely do this. I'd put the second block of code at the start of the exe script and have the exe run continuously.
First block of code:
Second block of code
First block of code:
Code: Select all
//Not sure how you know the name of the file but its unlikely
//it will be hard coded like this example. If you need help with that
//we'll need to know more about your naming convention.
Let>vFile=abc_todays date
IfFileExists>vFile
FileDate>vFile,vFileDate
MidStr>vFileDate,1,4,yyyy
MidStr>vFileDate,5,2,mm
MidStr>vFileDate,7,2,dd
FileTime>vFile,vFileTime
MidStr>vFileTime,1,2,hh
MidStr>vFileTime,3,2,mn
MidStr>vFileTime,5,2,ss
VBEVal>DateDiff("s","%mm%/%dd%/%yyyy% %hh%:%mn%:%ss%",now()),vSecondsOld
If>%vSecondsOld%>86400
//The file is more than 24 hours old so the script can continue.
Else
//The file is less than 24 hours old so exit the script.
Exit>0
EndIf
EndIf
//The rest of the script
Code: Select all
//Key down onEvent> to kill executable without having to go to Task Manager
//Key combination is WinKey + Esc
OnEvent>key_down,VK27,8,Quit
SRT>Quit
Exit>0
END>
Label>TheBeginningOfTheScript
Let>vFile=abc_todays date
IfFileExists>vFile
FileDate>vFile,vFileDate
MidStr>vFileDate,1,4,yyyy
MidStr>vFileDate,5,2,mm
MidStr>vFileDate,7,2,dd
FileTime>vFile,vFileTime
MidStr>vFileTime,1,2,hh
MidStr>vFileTime,3,2,mn
MidStr>vFileTime,5,2,ss
VBEVal>DateDiff("s","%mm%/%dd%/%yyyy% %hh%:%mn%:%ss%",now()),vSecondsOld
If>%vSecondsOld%>86400
//The file is more than 24 hours old so the script can continue.
Else
//The file is less than 24 hours old so wait 60 seconds then goto TheBeginningOfTheScript.
Wait>60
Goto>TheBeginningOfTheScript
EndIf
EndIf
//The rest of the script
//At the end of your script you need to return to the beginning so the script runs forever.
Goto>TheBeginningOfTheScript
Re: if file exists and is older than x hours
I really appreciate your time JRL.
The naming convention used is as follows and since the naming always changes i would need the code to detect this.
abc_17092017
abc_18092017
abc_19092017
the above naming would be what the patch file generates at the end of the exe script the time that the txt files are created varies. i hope this answers the naming convention.
a new txt file is created every day that the exe runs successfully so the there has to be a way to only check the age of the last file created.
The naming convention used is as follows and since the naming always changes i would need the code to detect this.
abc_17092017
abc_18092017
abc_19092017
the above naming would be what the patch file generates at the end of the exe script the time that the txt files are created varies. i hope this answers the naming convention.
a new txt file is created every day that the exe runs successfully so the there has to be a way to only check the age of the last file created.
Re: if file exists and is older than x hours
Can use the GetNewestFile> function. The following should get the latest file name and set it to variable "vFile"
Code: Select all
//Set the path to the files
//Leave off the final backslash
Let>vFilePath=YourDrive:\YourPath
GetNewestFile>%vFilePath%\abc_*,vFile
Re: if file exists and is older than x hours
almost there i really appreciate your patience.
i am still in testing phase. when i do this the code works fine
how do i make the use the file variable from
i tried i tried
many thanks for your help
i am still in testing phase. when i do this the code works fine
Code: Select all
Let>vFile=abc_todays date
IfFileExists>vFile
FileDate>vFile,vFileDate
MidStr>vFileDate,1,4,yyyy
MidStr>vFileDate,5,2,mm
MidStr>vFileDate,7,2,dd
FileTime>vFile,vFileTime
MidStr>vFileTime,1,2,hh
MidStr>vFileTime,3,2,mn
MidStr>vFileTime,5,2,ss
VBEVal>DateDiff("s","%mm%/%dd%/%yyyy% %hh%:%mn%:%ss%",now()),vSecondsOld
If>%vSecondsOld%>86400
//The file is more than 24 hours old so the script can continue.
Else
//The file is less than 24 hours old so exit the script.
Message>file not 24 hours old
wait>5
Exit>0
EndIf
EndIf
Message>file 24 hours old
wait>5
how do i make the
Code: Select all
Let>vFile=abc_todays date
Code: Select all
//Set the path to the files
//Leave off the final backslash
Let>vFilePath=YourDrive:\YourPath
GetNewestFile>%vFilePath%\abc_*,vFile
Code: Select all
Let>vFile=vFile
Re: if file exists and is older than x hours
Code: Select all
GetNewestFile>%vFilePath%\abc_*,vFile
Remove the line
Code: Select all
Let>vFile=
You want something like this. Make sure your path is correct.
Code: Select all
//Set the path to the files
//Leave off the final backslash
Let>vFilePath=YourDrive:\YourPath
GetNewestFile>%vFilePath%\abc_*,vFile
IfFileExists>vFile
FileDate>vFile,vFileDate
MidStr>vFileDate,1,4,yyyy
MidStr>vFileDate,5,2,mm
MidStr>vFileDate,7,2,dd
FileTime>vFile,vFileTime
MidStr>vFileTime,1,2,hh
MidStr>vFileTime,3,2,mn
MidStr>vFileTime,5,2,ss
VBEVal>DateDiff("s","%mm%/%dd%/%yyyy% %hh%:%mn%:%ss%",now()),vSecondsOld
If>%vSecondsOld%>86400
//The file is more than 24 hours old so the script can continue.
Else
//The file is less than 24 hours old so exit the script.
Message>file not 24 hours old
wait>5
Exit>0
EndIf
EndIf
Re: if file exists and is older than x hours
works like a charm.
once again thank you so much for all the time you spent helping me get this right.
once again thank you so much for all the time you spent helping me get this right.