about_IOInfoExtensions.PowerShell_GetDirectory.help.txt

TOPIC
    about_IOInfoExtensions.PowerShell_GetDirectory
 
SHORT DESCRIPTION
    Returns a [DirectoryInfo] object for a child directory with the specified name.
 
SYNTAX
    GetDirectory(string name, [bool resolve = False], [bool ignoreCase = True])
 
LONG DESCRIPTION
    Creates a new [DirectoryInfo] object referencing a child directory of the calling object. The newly created [DirectoryInfo] object will have the
    given 'name' and be validated against the remaining parameters.
 
    Specifying nested directories in 'name' is supported.
 
PARAMETERS
    name <System.String>
        The name of the child directory to return.
 
        Required: True
        Default Value:
        Accepts Wildcard Characters: False
 
    resolve <System.Boolean>
        If set to true the child directory's existance will be validated.
 
        Required: False
        Default Value: False
        Accepts Wildcard Characters: False
 
    ignoreCase <System.Boolean>
        If set to true the search for the child directory will be case in-sensitive.
 
        Required: False
        Default Value: True
        Accepts Wildcard Characters: False
 
OUTPUTS
    [System.IO.DirectoryInfo] referencing the desired child directory.
 
EXCEPTIONS
    System.ArgumentException
        If the
 
    System.Exception
        If the
 
    System.IO.DirectoryNotFoundException
        If the name
 
EXAMPLES
    --------------------- Example 1 ---------------------
    Get an existing child directory.
 
        $directory = New-Object System.IO.DirectoryInfo 'C:\Demo'
 
        Write-Host "First level children:"
        $directory.GetFileSystemInfos().FullName | ForEach-Object { Write-Host "`t$_" }
 
        $child = $directory.GetDirectory('ChildDir1')
        Write-Host "Child FullName:`n`t$($child.FullName)"
        Write-Host "Child Type:`n`t$($child.GetType().FullName)"
        Write-Host "Child Exists:`n`t$($child.Exists)"
 
        <#
        Output:
        First level children:
                C:\Demo\ChildDir1
                C:\Demo\ChildDir2
                C:\Demo\ChildFile1.txt
                C:\Demo\ChildFile2.txt
        Child FullName:
                C:\Demo\ChildDir1
        Child Type:
                System.IO.DirectoryInfo
        Child Exists:
                True
        #>
 
    This returns a [DirectoryInfo] object for the child directory named "ChildDir1". It uses default values for the 'resolve' and 'ignoreCase'
    parameters.
 
    --------------------- Example 2 ---------------------
    Get a non-existing nested child directory.
 
        $directory = New-Object System.IO.DirectoryInfo 'C:\Demo'
 
        Write-Host "Children:"
        $directory.GetFileSystemInfos("*", [System.IO.SearchOption]::AllDirectories).FullName |
            ForEach-Object { Write-Host "`t$_" }
 
        $child = $directory.GetDirectory('ChildDir3\InnerChildDir3')
        Write-Host "Child FullName:`n`t$($child.FullName)"
        Write-Host "Child Type:`n`t$($child.GetType().FullName)"
        Write-Host "Child Exists:`n`t$($child.Exists)"
 
        <#
        Output:
        Children:
                C:\Demo\ChildDir1
                C:\Demo\ChildDir2
                C:\Demo\ChildFile1.txt
                C:\Demo\ChildFile2.txt
                C:\Demo\ChildDir2\ChildFile1.txt
                C:\Demo\ChildDir2\ChildFile2.txt
        Child FullName:
                C:\Demo\ChildDir3\InnerChildDir3
        Child Type:
                System.IO.DirectoryInfo
        Child Exists:
                False
        #>
 
    This returns a [DirectoryInfo] object for the nested child directory named "ChildDir3\InnerChildDir3". It uses default values for the 'resolve' and
    'ignoreCase' parameters.
 
    --------------------- Example 3 ---------------------
    Resolve a child directory using case sensitivity.
 
        $directory = New-Object System.IO.DirectoryInfo 'C:\Demo'
 
        Write-Host "First level children:"
        $directory.GetFileSystemInfos().FullName | ForEach-Object { Write-Host "`t$_" }
 
        try
        {
            $null = $directory.GetDirectory('childdir1', $true, $false)
        }
        catch
        {
            $stringArgs = @(
                $_.Exception.GetType().ToString(),
                $_.Exception.Message,
                $_.Exception.StackTrace.Substring(0, $_.Exception.StackTrace.IndexOf([Environment]::NewLine))
            )
 
            Write-Host ("`nError: {0}: {1}`n{2}`n" -f $stringArgs)
            $error.Clear()
        }
 
        <#
        Output:
        First level children:
                C:\Demo\ChildDir1
                C:\Demo\ChildDir2
                C:\Demo\ChildFile1.txt
                C:\Demo\ChildFile2.txt
 
        Error: System.IO.DirectoryNotFoundException: A child named 'childdir1' already exists but with a different case: ChildDir1.
            at IOInfoExtensions.DirectoryInfoExtensions.GetDirectory(DirectoryInfo directory, String name, Boolean resolve, Boolean ignoreCase)
        #>
 
    Throws an exception because the existance and case sensitivity validations failed.
 
KEYWORDS
    IOInfoExtensions, IOInfoExtensions.PowerShell, System.IO.DirectoryInfo, DirectoryInfo, GetDirectory
 
SEE ALSO
    about_IOInfoExtensions.PowerShell
    about_IOInfoExtensions.PowerShell_GetDirectory
    about_IOInfoExtensions.PowerShell_GetFile
    about_IOInfoExtensions.PowerShell_DeleteContent
    about_IOInfoExtensions.PowerShell_CopyContentTo
    about_IOInfoExtensions.PowerShell_MoveFrom
    about_IOInfoExtensions.PowerShell_CopyFrom
    about_IOInfoExtensions.PowerShell_TryDelete