Community discussions

MikroTik App
 
fewi
Forum Guru
Forum Guru
Topic Author
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Working with file creation-time

Tue Aug 11, 2009 3:38 am

Hi,

I find myself having to check within a script whether a download via '/tool fetch' successfully finished. It seemed easiest to store the current time/date via '/system clock get time' and '/system clock get date', try to fetch the file and compare its creation-time, but despite the documentation claiming that the type of that attribute is 'time', on 3.28 I find that it's a string instead:
/system script> :put ("timestamp is " . [/file get [/file find name=test.txt] creation-time] . " and typeof creation-time is " . [:typeof [/file get [/file find name=test.txt] creation-time]]);
timestamp is aug/10/2009 16:46:03 and typeof creation-time is str
Is there any way to convert that string back into a time type variable? I was only able to cast strings like '8h4m36s' but cannot figure out how to add a date portion to that.

Or am I overlooking a far simpler method to detect whether the download successfully finished?

Thanks,
Felix
 
fosben
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: Thu Dec 14, 2006 4:50 pm

Re: Working with file creation-time

Thu Aug 13, 2009 11:24 am

What if your downloadscript wrote "finished" in a log or to a txt file ? If I remember correctly the script wait for the download to complete before executing the rest of the script, not sure what happends if connection is lost though..

Why creation time and not file size ?
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: Working with file creation-time

Thu Aug 13, 2009 6:40 pm

'totime' function?..
 
fewi
Forum Guru
Forum Guru
Topic Author
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Working with file creation-time

Thu Aug 13, 2009 10:35 pm

What if your downloadscript wrote "finished" in a log or to a txt file ? If I remember correctly the script wait for the download to complete before executing the rest of the script, not sure what happends if connection is lost though..

Why creation time and not file size ?
Because if the file download fails due to a 404 (for example), previously downloaded files with the same name stick around and have their original file size. If nothing else works I can delete the file after processing and simply check for existence after a download, but for our business process it's far preferable to keep the file around.
'totime' function?..
How do you use [:totime] on a string such as "aug/13/2009 17:02:03"? I was only able to convert strings such as "17h02m03s" (which I could construct from "17:02:03"), and couldn't get anywhere with dates at all. Since the last successful download may have been on the previous day, simply comparing times instead of datetimes is insufficient.
 
fewi
Forum Guru
Forum Guru
Topic Author
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: Working with file creation-time

Thu Aug 13, 2009 10:36 pm

Also, thank you for your time.
 
fosben
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: Thu Dec 14, 2006 4:50 pm

Re: Working with file creation-time

Thu Aug 20, 2009 2:40 pm

Just create varables for day, month and year and use string manipulation to fill in those variables from your creationtime, then compare those values to current date..

Who is online

Users browsing this forum: Bing [Bot] and 24 guests