< Back

New-TempDirectoryTree

Sun Jan 12, 2020 5:54 pm

NAME New-TempDirectoryTree



SYNOPSIS

Creates a directory tree using a custom DSL.





SYNTAX

New-TempDirectoryTree [-Tree] <String> [-Prefix <String>] [<CommonParameters>]



New-TempDirectoryTree [-Tree] <String> -Path <String> [<CommonParameters>]





DESCRIPTION

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.





PARAMETERS

-Tree <String>

The directory tree to create.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Prefix <String>

An optional prefix for the temporary directory's name.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Path <String>

The path where the directory tree should be created. Defaults to a new directory in the `$env:TEMP` directory.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

System.IO.DirectoryInfo.





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>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.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>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'









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>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.











RELATED LINKS