Export (0) Print
Expand All
Expand Minimize

Converting the FileSystemObject's IsRootFolder Property


Windows PowerShell


Definition: Returns True if the specified folder is the root folder.

IsRootFolder


We don’t know of a similar property in PowerShell or the .NET Framework, but you can find the root of a folder, and if that root is equal to the folder, then the folder is the root. Something like this:


$folder = "C:\"
$a = New-Object -typename System.IO.DirectoryInfo $folder
if ($folder -eq $a.root.name)
{
    "$folder is a root folder."
}
else
{
    "The root of $folder is " + $a.root.name
}


We start by setting the variable $folder to the folder we want to check. We then use the New-Object cmdlet to retrieve a reference to the DirectoryInfo of that folder. At that point we can check the Name property of the Root for that folder. If the name of the root is the same as the folder, then the folder is the root. Otherwise we display the name of the root for that folder.


See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft