Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Test-Path returns $False while file exists.

$
0
0

Hello all,

I found that Test-Path returns a $False even when a file exists. I created c:\temp\input.csv but it is not recognised by the script.

Clear-Host
Write-Host "Test-Path"
$FileName = "C:\temp\input.csv"
if(Test-Path -Path $FileName)
{ Write-Host "The file $FileName exists"} else { Write-Host "The file $FileName does not exists." }

Write-Host "[System.IO.DirectoryInfo]"
[System.IO.DirectoryInfo]$file = "c:\temp\input.csv"
$Froot    = $file.Root.ToString()
$Fparent  = $file.Parent.ToString()
$Fname    = $file.Name.ToString()
$FullName = $Froot + $Fparent + "\" + $Fname
if(Test-Path -Path $FullName)
{ Write-Host "The file $FullName exists"} else { Write-Host "The file $FullName does not exists." }

And a picture:

I do something wrong here, but what?

Any help is appreciated.

With kind regards,

Willem-Jan


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>