Create a task scheduler that triggers a task if a csv file is created

Brass Contributor

Hi All,

Many thanks in advance, I have a powershell script that runs based on an input csv file. I have to run the script once a csv file is created, kindly help me by letting me know hos to trigger a task based on csv file creation.

3 Replies
best response confirmed by PoorMens_Bravo (Brass Contributor)

@PoorMens_Bravo Personally, I would add to the PowerShell code a check for the existence of the CSV file(s) and progress only if it exists, otherwise quit. You would then also need to set the task to run more frequently. 


if (Test-Path -Path C:\SomeFileName.csv -PathType Leaf){"found, do something"}Else{"quit"}


Apologies if I misunderstood requirements. 

Thanks for the suggestion, I thought about this idea initially, but, was worried about the after effects, like what about the load on the server of these repeated tasks??
Like @CLCCW said,
You could also put your whole code in an endless loop
if (Test-Path -Path C:\SomeFileName.csv -PathType Leaf){
"found, do something"
Sleep 5

With the above it checks every 5 seconds if a file exists and if it does it does whatever you want otherwise sleeps 5 seconds again.
Not the most elegant way, but it would work.
I am also looking into a solution where a script is triggered if a file is created in a folder.
Something a bit more reliable , like your scheduled task.
Or you and me could set up a scheduled task to run every hour to run this endless script with the option to not run if the task is already running.