I am trying to complete a simple of task of looking at a source folder for certain file extensions and if each file doesn't exist in the Destination, copy the file.
The code i am using is below and this works however the "test-path" section doesn't work as it always copies the files. This seems such a simple task and no mount of searching online has helped at all.
#Source(s) and Destination(s) of files to use attributed to different variables.$source = "C:\Folder1"
$dest = "C:\Folder2"
#Groups files of a certain extension into variables to use later
$srctxt = Get-ChildItem $source -Filter *.txt
foreach ($file in $srctxt)
{
If(!(Test-Path -path "$dest))
{
"Files Exists - No further action required"
}
else
{
"Files do not exist. Missing files will now be copied"
Copy-Item -Path $source\*.txt -Destination $dest -Verbose
}
}
Appreciate your help