You have an Event like File Modified / File Created that fires for any file in a folder. You want the task to continue only if the file ends with .txt, and otherwise exit immediately.
Where the file path comes from For file events (File Modified, File Created, File Moved, etc.), Tasker puts the full file path into the built‑in variable %evtprm1.
Example:
If /storage/emulated/0/Download/test.txt is modified, %evtprm1 will contain that whole path.
Simple version using Variable Search/Replace This is usually the easiest to read and edit later.
ProfileContext:
Event → File → File Modified (or Created/Moved)
File: point to the folder or file you’re watching.
Task actionsA1 – Variable Search ReplaceAdd action: Variables → Variable Search Replace.Variable: %evtprm1Search: .txt Ignore Case: OffMulti-Line: OffOne Match Only: On (doesn’t really matter here)Store Matches In: %match (or any local variable name)Replace Matches: Off
Effect:If the file path contains .txt, %match will be set.If not, %match will be empty.
A2 – IfAdd action: Task → If.Condition: %match Is Set
This creates an If block; everything between If and End If only runs for .txt files.
A3 – [Your real actions here] Put whatever you actually want to do with .txt files here.
A4 – End IfAdd action: Task → End If.
Result:When the event fires for a .txt file → %match is set → your actions run.For other file types → %match is not set → the task basically does nothing.
```
This runs efficiently since filtering happens first.
Alternative: Directory Monitor
Use a looped task with List Files on the folder, comparing timestamps or counts against globals like `%LastTxtCount`. Trigger via Time context (every 5-10s). Less battery-friendly but fully filterable by extension in JavaScriptlet:
```
var files = files(); // From List Files
var txtCount = 0;
for (var i = 1; i <= files.length(); i++) {
if (files(i).match(/\.txt$/)) txtCount++;
}
if (txtCount > %par1) { setGlobal("TxtChanged", 1); }
```
Pass prior count via Perform Task. Cleaner for high-activity folders.
Hope this helps a little