Reputation: 13
I am trying to run a check in power shell to see if a file exists, and if so copy it to another location and if other wise just print an error message to the screen.
if (Test-Path "Z:\Network Folder\Another Folder\"FileInQuestion.docx") {
Write-Host "Contents exist and and will be copied!"
} else {
Write-Host "ERROR: Cannot find file."
}
Upvotes: 0
Views: 137
Reputation: 59
Sorry for what I replyed last time,I didn't see carefully
Try this test-path "\\network folder\another folder\YourFiles.docx"
Usually,We don't use z:\
,unless it is a real path. You said it is a network path.
\"FileInQuestion.docx"
there is more "
in that path
Had you ever used Net-Use
command before you used test-path
?
Upvotes: 1