Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - Test-Path if a file exists within a folder

$
0
0
Hey Guys,

I'm unable to get this to work correctly. I'm trying to see which folders have a file within them with the word "preview".  If it does, then tell me it exists, if not, then it doesn't exist.

What am I missing?!? Ugh :(

Here is my code

$rootpath = "T:\Path1\Path2\*" 


foreach ($f in Get-ChildItem $rootpath)
{
	foreach ($i in Get-ChildItem $f)
	{
		if (Test-Path $i -include *preview*.jpg)
		{
			echo($i.name + "           Preview Exists")
		}
		else
		{
			echo($i.name + " ***PREVIEW MISSING***")
		}
	}
}

Viewing all articles
Browse latest Browse all 15028

Trending Articles