I have a script which moves files with a specific extension from a source directory to a destination directory.
My source directory looks like:
FILESFOLDER
File1.td
File2.td
SUBFOLDER
File3.td
File4.td
My script is short and looks like:
if(!(Test-Path $SourceDirPath) -or !(Test-Path $DestinationDirPath))
{
Write-Host "The source- or destination path is incorrect, please check "
break
}else
{
Write-Host "Success"
Copy-Item -path $SourceDirPath -Filter "*$extension" -Destination $DestinationDirPath -Recurse
}
I have to mention that the $SourceDirPath
comes from a config file and only works if I declare it as C:\FILESFOLDER\*
The script works but doesn't copy the files from the subfolder to destination. The destination only has File1 and File2.
What's wrong with my Copy-Item command?