Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Asynchronously monitor the contents of a folder for the appearance of new files
ResourceFunction["MonitorFolder"][path,fn] asynchronously monitor the folder path and apply fn to any new files that appear. |
| UpdateInterval | 1 | time between checks of the folder |
| "FilePattern" | "*" | kinds of files to watch for |
Print out the file names of any new files that appear in the Pictures folder:
| In[1]:= |
| Out[1]= | ![]() |
To stop monitoring the folder use TaskRemove:
| In[2]:= |
| Out[2]= | ![]() |
By default the folder is checked every second. To check less frequently use the option UpdateInterval:
| In[3]:= |
| Out[3]= | ![]() |
All new files are detected, but a "FilePattern" option allows only specific files to be watched for. For example only watch for files ending in ".txt":
| In[4]:= |
| Out[4]= | ![]() |
If any new images appear in the Pictures folder, display their contents in a new window:
| In[5]:= |
| Out[5]= | ![]() |
The monitoring is performed by a ScheduledTask and so will be performed even if the kernel is busy with another operation:
| In[6]:= |
This work is licensed under a Creative Commons Attribution 4.0 International License