1

Is there a way to add a time delay to this script to move the .pdfs.? So when multiple PDf's are dropped into the transfer folder wait 10 seconds before it transfers the file(s)

$folder = 'C:\Transfers'  
$filter = '*.PDF'   

$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}

Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { 
$name = $Event.SourceEventArgs.Name 
$changeType = $Event.SourceEventArgs.ChangeType ## Heading ##$timeStamp = $Event.TimeGenerated 
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green 
write-host "test"
Invoke-Item 'C:\Transfers\Movebat.bat'}
3
  • Maybe Wait-Event and a Timer as per learn.microsoft.com/en-us/powershell/module/… Commented Sep 24, 2020 at 16:41
  • or add Start-Sleep -Seconds 10 before moving? Commented Sep 24, 2020 at 16:50
  • Where in the script do I add the "Start-Sleep -Seconds 10" Commented Sep 24, 2020 at 17:04

1 Answer 1

1

Use the sleep cmdlet.

For seconds: sleep -s 10

For milliseconds: sleep -m 10000

Sign up to request clarification or add additional context in comments.

2 Comments

Where in the script do I add it?
According to this: "when multiple PDf's are dropped into the transfer folder wait 10 seconds before it transfers the file(s)" I would put it right before you call the bat file with invoke-item. If that doesn't work you can also do a sleep in the .bat file with timeout /t 10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.