I have a Powershell script doing the following:
# Lists txt files, remove 'newline' in files, move them to another folder
$files = @(Get-ChildItem c:\temp\*.txt)
$outputfolder = "c:\temp\fixed"
foreach ($file in $files)
{
(Get-Content $file -Raw) -replace "`n",'' | Set-Content $file
Move-Item $file $outputfolder
}
Now I would like to add some while cycle (or other routine) with the aim to keep the script awake and listening for new files to be processed. When new incoming files are detected in c:\temp folder the script should process them automatically. Maybe it could be achieved using some "sleep" command, to check the directory every 5 seconds.
Some good suggestion?