how does the powershell process test the contents of the directory tree?

# The name of the file to look for.
$fileName = 'somefile.txt'

# Where to start looking (the current dir).
$dir = $PWD.ProviderPath

# Walk up the directory hierarchy until the first file whose name
# matches $fileName is found, and return that file's path.
# If no such file is found, $file is (effectively) $null.
$file = 
 do { 
   if (Test-Path -Type Leaf -LiteralPath ($file = "$dir/$fileName")) { 
     $file # output the path of the file found.
     break # exit the loop
   }
 } while ($dir = Split-Path -LiteralPath $dir)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top