Run script when a file exists

Hi All,

I’m trying to run a script based on whether a file exists or not. I can target it at a specific folder but wondered if it’s possible to search subfolders in the threshold. The box says file name or search string but I’m not sure what to put in to search for a file

image

The idea is to automate the moving of a folder and subfolders to another location. The initial idea is to create a specifically named text file to trigger the script. The script then closes any open files and moves the folder.

But there are lots of folders inside the root directory that the text file could be in. Might not be possible but thought I’d ask. Or someone might have a much better idea :slight_smile:

Thanks
Rich

The file acceabiltiy tool is used to check if a specific file exists, can be written to and opened. It doesnt work they way you want it too. At least not yet.( Submit a feature request to check subfolders )

But, you could do this with a custom tool.
Make a tool in your tool box to check for the file via powershell, then use that in your alert as Custom trigger. https://simple-help.com/management-guide#Custom-(Scheduled-Tools)

Guide for using powershell if file exists: https://www.itechguides.com/powershell-check-if-file-exists/

Example script for tool:
$Return = Get-ChildItem E:\reports | Where-Object { ($.PSIsContainer -ne $true) -and ($.Extension -eq “.log”)}

Thanks, that’s better idea than mine :grinning:

I’ll have a look at the Powershell and attempt to put it all in one script and see if it works!

Once you get it working be sure to post your findings and a finished example. I am sure others will appreciate it. :slight_smile: