To check if file or folder exists in Powershell you can use the following snippet.

Sample Powershell

for files use it like this

if(test-path "C:\Users\Codesnippets\Desktop\Test.xml") 
{ 
	echo "exists!" 
} 
else 
{ 
	echo "not exists!" 
}

for folders/directories use it like this

if(test-path "C:\Users\Codesnippets\Desktop") 
{ 
	echo "exists!" 
} 
else 
{ 
	echo "not exists!" 
}

2 thought on “How to check if file or folder exists in Powershell”

Leave a Reply