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 representing a child directory of the calling <DirectoryInfo> object that has the specified name. The newly created <DirectoryInfo> object will be checked against the remaining parameters as specified then returned. Specifying nested directories in the 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, it will throw an error if a matching child directory is not found. Required: False Default Value: False Accepts Wildcard Characters: False ignoreCase <System.Boolean> If set to false, it will throw an error if a matching child directory is found but with a different case. Required: False Default Value: True Accepts Wildcard Characters: False OUTPUTS System.IO.DirectoryInfo EXCEPTIONS System.ArgumentException If the given name is null, empty, or just whitespace. System.Exception If the given name matched multiple child items. This will happen if a wildcard was passed as part of the name. System.IO.DirectoryNotFoundException If the given name resolves to a child file, resolve = true and the child directory does not exist, or if ignoreCase = false and the casing doesn't match. EXAMPLES --------------------- Example 1 --------------------- Get an existing child directory by specifying only the directory name using the correct casing. PS> $directory = New-Object System.IO.DirectoryInfo 'C:\Demo' PS> $directory.GetFileSystemInfos().FullName C:\Demo\ChildDir1 C:\Demo\ChildDir2 C:\Demo\ChildFile1.txt C:\Demo\ChildFile2.txt PS> $child = $directory.GetDirectory('ChildDir1') PS> $child.FullName C:\Demo\ChildDir1 PS> $child.GetType().FullName System.IO.DirectoryInfo PS> $child.Exists True This returns a <DirectoryInfo> object for the child directory named "ChildDir1" in the given directory. It uses default values for the <resolve> and <ignoreCase> parameters. --------------------- Example 2 --------------------- Get a non-existing child directory by specifying only the directory name. PS> $directory = New-Object System.IO.DirectoryInfo 'C:\Demo' PS> $directory.GetFileSystemInfos().FullName C:\Demo\ChildDir1 C:\Demo\ChildDir2 C:\Demo\ChildFile1.txt C:\Demo\ChildFile2.txt PS> $child = $directory.GetDirectory('ChildDir3\InnerChildDir3') PS> $child.FullName C:\Demo\ChildDir3\InnerChildDir3 PS> $child.GetType().FullName System.IO.DirectoryInfo PS> $child.Exists False This returns a <DirectoryInfo> object for the child directory named "ChildDir3\InnerChildDir3" in the given directory. It uses default values for the <resolve> and <ignoreCase> parameters. 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 |