I want to find which files are recently modified in a specific directory. For this purpose, I wrote a function named Test.
The function's argument is DirectoryPath, and it returns file names whose file dates have been modified. In this example the functions runs once every five seconds.
For this purpose I wrote the following code, but it shows all the file names that are in the directory. That means it doesn't check the ModificationDate with lastModified.
Test[directoryPath_] := Module[{taskId,
fileNames = FileNames["*", SystemDialogInput["Directory"]],
lastModified,
result},
(
lastModified = Table[{}, {Length[fileNames]}];
result = Table[{}, {Length[fileNames]}];
taskId =
CreateScheduledTask[
Table[(With[{
i = i,
modificationDate =
Table[FileDate[Part[fileNames, j], "Modification"],
{j, 1, Length[fileNames]}]
},
(If[(Part[lastModified, i] === Part[modificationDate, i]),
(Part[result, i] = ""),
(Part[lastModified, i] = Part[modificationDate, i];
Part[result, i] = Part[fileNames, i])])]),
{i, 1, Length[fileNames]}],
{OptionValue[ScanRate], \[Infinity]}];
StartScheduledTask[taskId];
{taskId, Dynamic[result]}
)]
Test[SystemDialogInput["Directory"]]
How can I solve this?
ScheduledTask? If not, then you'd better simplify the code to run without it. Here are some potential problems that you want to investigate: a) usingfileNamesin the RHS of the local variable definitions ofModulemost probably doesn't do what you expect. b) comparing the result ofFileDatedoesn't look right, I'd rather suggest to convert it to anAbsoluteTimeand check with e.g.>. – Albert Retey Mar 13 at 9:33