Guides / Run a script when a file is added
Guide / Workflow

Run a script when a file is added to a folder on Windows

By Param Nimbark. Last updated 2026-10-12.

Running a script when a file is added to a folder on Windows sounds like a Task Scheduler job, but Task Scheduler has no trigger for a file or folder change: its triggers are time based or tied to startup, logon, idle and event log entries. So people end up polling every few minutes, or writing a PowerShell watcher that dies the moment the window closes. This guide gives the honest PowerShell way with FileSystemWatcher, lists where it breaks, and then shows the Seqtrix way: a File Watch trigger that watches a folder or a whole tree, filters by name or extension, and runs any sequence, your script included, with no code.

Get it from Microsoft Store

Installs from the Microsoft Store, no SmartScreen prompt. Free Starter plan, no account.

Download the installer (211 MB)

Direct installer for Windows 10 and 11, 64-bit, v0.16.0.

See the six trigger types

The manual way: a PowerShell FileSystemWatcher

Windows itself does watch folders; the capability is exposed to scripts through the .NET FileSystemWatcher class, which raises Created, Changed, Deleted and Renamed events for a directory and, if you ask, its subdirectories. PowerShell subscribes to those events with Register-ObjectEvent. Open PowerShell and paste this, changing the folder, the filter and the script path:

$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "$env:USERPROFILE\Downloads"
$watcher.Filter = "*.pdf"
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $true

Register-ObjectEvent -InputObject $watcher -EventName Created -SourceIdentifier NewPdf -Action {
  $file = $Event.SourceEventArgs.FullPath
  & "C:\Scripts\file-invoice.ps1" -Path $file
}

# Keeps the session alive. Close the window, or run Unregister-Event NewPdf, to stop.
Wait-Event

Filter picks which names count, IncludeSubdirectories widens it to the whole tree, and the Action block is what runs, with the new file's full path in the event's arguments. This works, and for a developer it takes a few minutes. The problems start after it works.

Where the watcher breaks

It lives and dies with the window

Microsoft’s Register-ObjectEvent reference states that events, subscriptions and the event queue exist only in the current session; close it and the subscription is cancelled. Signing out or rebooting does the same, so the watcher must be restarted every time, which usually means a Task Scheduler task at logon, a hidden window and an execution policy to sort out.

Created fires before the file is finished

The event is raised when the file appears, which for a large download or a copy over the network is before the last byte lands. Your script opens a half-written file unless you add your own wait-and-retry loop.

One change can be several events, and some get lost

Microsoft’s FileSystemWatcher remarks note that common operations such as a move can raise several events, that antivirus software can add more, and that if many changes land at once the internal buffer overflows and the watcher loses track of changes. Your script has to tolerate running twice, and occasionally not at all.

Every variation is more code

Only PDFs with "invoice" in the name? A second filter. Different folders? A second watcher. Move the file, then encrypt it, then open it? Three more blocks, each with its own error handling. The script that started as six lines grows into a tool you now maintain.

And Task Scheduler's limit

Microsoft's Task Triggers reference lists what can start a task: time-based triggers (once, daily, weekly, monthly) and event-based triggers such as system startup, a user logging on or the system becoming idle. A file landing in a folder is not on the list. The two workarounds are a task that repeats every few minutes and checks the folder, which is slow and wasteful, or an event log trigger fed by file auditing, which is a project in itself.

The Seqtrix way: a File Watch trigger

Seqtrix is a Windows automation app where a trigger is something you attach to a sequence, not something you code. File Watch is one of its six trigger types. You pick a folder, pick the event (create, modify, delete or any), tick include subfolders to watch the whole tree, and add a name filter: a comma-separated list such as *.pdf,*.docx, a bare extension such as .jpg, or a word such as invoice. Matching is case-insensitive. Seqtrix also collapses the burst of events a single save generates into one run, so the sequence fires once per file.

The sequence then does the work. A Run Command step runs your existing PowerShell script with the path you choose, or you skip the script entirely and use the built-in steps: move the file, encrypt it, open it in an app, type a note, send a key press. File Watch triggers are part of the Advanced plan ($4.99 per 30 days, paid once, no subscription) and of the 15-day trial every install starts with.

From template

Open Templates in Seqtrix, search for Sort my Downloads folder, then choose Use template (click the card). The sequence creates a Sorted folder inside Downloads with Documents, Images, Installers and Archives underneath, files each download by type using robocopy with /MOV so nothing is ever deleted, counts what went where, and opens the result. It is an Advanced template. On its own it runs when you click it; attach a File Watch trigger on your Downloads folder with the create event and it runs itself every time a download lands.

Or wire up your own script in four steps

  1. 1
    Install Seqtrix

    Download Seqtrix v0.16.0 for Windows 10 or 11. Every install includes a 15-day trial of the Advanced plan, with no card and no account needed to begin.

  2. 2
    Build the sequence

    Create a new sequence. Add a Wait step if the files are large, then a Run Command step that runs your script, for example powershell -NoProfile -File "C:\Scripts\file-invoice.ps1". Or replace the script with built-in steps.

  3. 3
    Attach a File Watch trigger

    In the sequence’s triggers, add File Watch. Choose the folder, set the event to create, add a name filter such as *.pdf and tick include subfolders if the files can land in subfolders. Save.

  4. 4
    Drop a file in and watch the run report

    Copy a matching file into the folder. The sequence fires, and the run report shows each step and what it returned, so a failing script is visible rather than silent. Seqtrix has to be running for triggers to fire.

What people actually watch folders for

The same trigger, pointed at different folders, replaces a surprising number of scripts:

  • • Invoices: a new PDF in Downloads moves to the Invoices folder and opens for a look.
  • • Camera imports: a card import lands and the File my photos by month template files everything by date.
  • • Cloud staging: a file dropped in a staging folder is encrypted with AES-256-GCM before the sync client ever sees it, using the Security Lock step.
  • • Build output: an artifact updated in a dist folder runs your deploy script, with the report kept.

FAQ

Can Windows Task Scheduler run a script when a file is added to a folder?

Not directly. Microsoft documents Task Scheduler triggers as time based (once, daily, weekly, monthly) or event based (system startup, a user logging on, the system going idle, an event log entry). There is no trigger for a file or folder change. The usual workarounds are a task that repeats every few minutes and checks the folder, or a task that starts a PowerShell watcher at logon and hopes it stays running.

Why does my PowerShell FileSystemWatcher stop working?

Because the event subscription lives in the PowerShell session that created it. Microsoft’s Register-ObjectEvent reference notes that if you close the session, the event queue is discarded and the subscription is cancelled. Closing the window, signing out or rebooting all end the watcher, so it has to be started again every time, usually by yet another scheduled task.

Does File Watch in Seqtrix need any code?

No. File Watch is a trigger you attach to a sequence: pick the folder, pick the event (create, modify, delete or any), optionally include subfolders and add a name filter. The sequence then does the work with built-in steps such as Run Command, Security Lock or Open Application. If you already have a script, a Run Command step runs it with the path you choose.

Can Seqtrix watch subfolders and filter by file type?

Yes. Tick include subfolders to watch a whole folder tree, and use the name filter to narrow it: a comma-separated list such as *.pdf,*.docx, a bare extension such as .jpg, or a plain word such as invoice that matches anywhere in the file name. Matching is case-insensitive, and Seqtrix collapses the burst of events a single save generates into one run.

Will the script run before the file has finished copying?

It can, with any watcher. Windows raises the create event when the file appears, which for a large download or a copy over the network is before the last byte lands. In Seqtrix the fix is a Wait step before the step that uses the file; in raw PowerShell you write the retry loop yourself.

Keep going

Watch your first folder in minutes

15-day Advanced trial on every install. No credit card, no scripting, offline by default. Telemetry stays off unless you turn it on in Settings > Privacy.

Get it from Microsoft Store

Installs from the Microsoft Store, no SmartScreen prompt. Free Starter plan, no account.

Download the installer (211 MB)

Direct installer for Windows 10 and 11, 64-bit, v0.16.0.