Creates a directory tree using a custom DSL.
New-TempDirectoryTree [-Tree] <String> [-Prefix <String>] [<CommonParameters>]
New-TempDirectoryTree [-Tree] <String> -Path <String> [<CommonParameters>]
Use this function to setup a quick directory/file structure in the current temporary directory for a test using a concise DSL. The directory structure is specified in a string. Each item for the directory tree should be on its own line. Directory names should be prefixed with +
. Files should be prefixed with *
. Items that should be within a parent directory should be indented two spaces from the position of its parent. A quick example will probably show it better:
+ RootDir
* ChildFile.txt
+ ChildDir
* GrandchildFile.txt
* GrandchildFile2.txt
* RootFile.txt
Easy! A System.IO.DirectoryInfo
object is returned for the directory which contains your new directory/file tree.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Tree | String | The directory tree to create. |
true | false | |
Prefix | String | An optional prefix for the temporary directory's name. |
false | false | |
Path | String | The path where the directory tree should be created. Defaults to a new directory in the |
true | false |
New-TempDirectoryTree -Tree "+ RootDir`n*RootFile.txt"
Creates the following directory tree in its own directory under the current user's temporary directory:
+ RootDir
* RootFile.txt
The directory name is randomly generated.
New-TempDirectoryTree -Tree "* File1`n* File2" -Prefix 'Test-FilesSkipped'
Creates the following directory tree in its own directory under the current user's temporary directory:
* File1
* File2
The directory name (randomly generated) is prefixed with Test-FilesSkipped
, e.g `Test-FilesSkipped53q5rekv.kab'
New-TempDirectoryTree -Tree "+ Dir1`n + Dir 2`n + Dir3" -Path 'C:\Projects\Blade\Test\Test-TempDirectoryTree'
Creates the following directories in the C:\Projects\Blade\Test\Test-TempDirectoryTree
directory:
+ Dir1
+ Dir2
+ Dir3
If Path
doesn't exist, it is created.