Rotten Code

it can always work better - but at least it should work

  Home  |   Contact  |   Syndication    |   Login
  18 Posts | 0 Stories | 12 Comments | 2 Trackbacks

News



Archives

Recommended Podcasts

Wednesday, August 06, 2008 #

So you want to determine if a folder or file exists with PowerShell? You can invoke the same scripting object you might remember from VB....


#set a var for the folder you are looking for
$folderPath = 'C:\Temp\'

#instantiate the FileSystemObject
$objFSO = New-Object -ComObject Scripting.FileSystemObject

#check to see if it is missing
if($objFSO.FileExists($folderPath -eq $FALSE))
{
     echo "The folder does not exist."
     exit
}
else
{
    echo "The folder exists."
    exit
}
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati