I am trying to get file path from the user and concatenating the file name and creating that file in the folder and then checking if the file exists. File is created and path looks correct to me but when I try to check if file path exists using test-path, it keeps failing that it does not exist
I can see the file and it exists in my system. When I copy the path and try to open in windows explorer, it gives me an error but when I try to right click on the file and copy the name and then check in windows explorer, it works. I am not sure if concatenation is adding some special characters.
$fileName = Read-Host -Prompt 'Enter file Name :' #user entered Test123
$filePath = Read-Host -Prompt 'Enter Path:' #user entered C:\Documents
$File = ($filePath + "\" + $fileName + ".json")
If (!(test-path $File)) {
Write-Host "File does not exist"
Exit
}
What am I doing wrong? I am trying to get path from user and concatenating the file name and creating that file in the folder and then checking if the file exists
Your concatenation is not valid.
Based on our exchange below, removed the original response, now that you've clarified your use case.
Or