I'm doing a few small school assignments, but our teacher is doing a pretty bad job in explaining stuff, so I've basically just been googling watching videos etc.
But I have to make a script that copies a file from one path to another, and it has to give an error if the file doesn't exist. I've written this piece of code:
$testpath = Test-Path $destinationfolder
$startfolder = "C:\Desktop\Destination1\test.txt\"
$destinationfolder = "C:\Desktop\Destination2\"
If ($testpath -eq $true) {Copy-Item $startfolder -Destination $destinationfolder}
Else {Write-Host "Error file does not exist!"}
My problem is that when it successfully copies the file, it still prints out the error. Its almost like it completely ignores the if and else statements. Can someone please, explain to me what i'm doing wrong, so i can correct it and hopefully learn something today? :)