Check if a file exists or not in Windows PowerShell?

后端 未结 7 1563
自闭症患者
自闭症患者 2020-12-03 02:38

I have this script which compares files in two areas of the disk and copies the latest file over the one with the older modified date.

$filestowatch=get-con         


        
7条回答
  •  借酒劲吻你
    2020-12-03 02:57

    Use Test-Path:

    if (!(Test-Path $exactadminfile) -and !(Test-Path $userfile)) {
      Write-Warning "$userFile absent from both locations"
    }
    

    Placing the above code in your ForEach loop should do what you want

提交回复
热议问题