jeudi 25 janvier 2018

Unable to correctly move file base on LastWriteTime

I have an if / elseif statement in which I would like to copy files only if they match the name and the file in the source is newer than the file in the destination.

I have manually checked the LastWriteTime of both files, and the source is older, so the file should not move. I think there may be a fault in my logic.

foreach($file in $files){

elseif(($fileList -contains $fileName) -and ($destination -contains $fileName)){
GCI $destination\*.jpg | Where-Object {$_.name -like $fileName -and $_.LastWriteTime -gt $fileName.LastWriteTime}    
    Copy-Item $file $destination  
        }
}

I did not include the if block because it is functioning. Additionally I have tried -gt and -lt both of which move the file, so something must be wrong with my where-object or something... Been working on this for too long, and could use some help!

Thanks

Aucun commentaire:

Enregistrer un commentaire