0

I am facing the following issue and I would really appreciate some help on that one.

I am automatically receiving 5 .csv files that I want to move to specific target folders. I want to only move them once I am certain that all of them are present. If one is missing, I don't want to move any of them. I tried the following code but the if statement is not working as expected. How can this be fixed?

$files = Get-ChildItem C:\directory -Filter *.csv

$filecheck = "C:\directory file.csv", 
                "C:\directory\file(1).csv",
                "C:\directory\file(2).csv",
                "C:\directory\file(3).csv",
                "C:\directory\file(4).csv"

$result = ($filecheck | Test-Path) -notcontains $false

if($result = $true) {
   {$_.Name -like 'file.csv'} {
        $_ |Move-Item -Destination 'C:directory\targetFolder'
        }

repeat for all files ...
}
Squary94
  • 248
  • 2
  • 16
  • 1
    Change `if($result = $true)` to `if($result -eq $true)` – Daniel Sep 29 '21 at 14:17
  • 1
    In short: In PowerShell, use `-eq` / `-ne` for equality / inequality comparisons; `=` is only used for _assignments_. See [this answer](https://stackoverflow.com/a/44248005/45375) to the linked duplicate. – mklement0 Sep 29 '21 at 14:23

0 Answers0