Group Abstract Group Abstract

Message Boards Message Boards

1
|
8.1K Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Running a scheduled task on a file directory to see if files added

Posted 5 years ago

Is there anyway to run scheduled task on directory at a certain time interval to see for file additions? The below code was found at https://mathematica.stackexchange.com/questions/15935/execute-code-when-file-is-modified/15938 and seems to not work anymore.

Begin["Kale`"];
    fileName = "~/foo.txt";
    lastModified = {};
    updatedQ := With[{modificationDate = FileDate[fileName, "Modification"]}, 
        If[lastModified == modificationDate, False, lastModified = modificationDate; True]];
    task = CreateScheduledTask[If[updatedQ, Print["Changed"], ## &[]], {2, ∞}];
End[];

StartScheduledTask[Kale`task];
StopScheduledTask[Kale`task];
POSTED BY: Luke Jennings
2 Replies
Posted 5 years ago
POSTED BY: Joel Klein
Posted 5 years ago

Hi Luke,

Probably because CreateScheduledTask is deprecated (unless you are on V11.2/3). You will have to re-write that code to use SessionSubmit.

POSTED BY: Rohit Namjoshi