Check if file exists, then move it

Dem*_*yan 3 powershell

I'm trying to write a few lines of code in powershell, to check if a file arrived to a specific folder. If the file is there, copy it to another folder. No action required if the file is not there. So far I have only the copying part:

cd C:\
Move /y "C:\myfolder\*.csv" "C:\MyDestinationFolder"
Run Code Online (Sandbox Code Playgroud)

I can't find a simple code to check if the file is present.

小智 5

Maybe you can use this:

$SourceFile = "C:\source\file.txt"
$Destination = "C:\destination\"

if(Test-Path -Path $SourceFile)
{
    Copy-Item -Path $SourceFile -Destination $Destination
}
Run Code Online (Sandbox Code Playgroud)