Skip to content

$cs.File_CreateDirectory

Creates the directory at path, including any missing parent directories, if it doesn’t already exist. If it already exists, nothing happens — no error is raised.

$cs.File_CreateDirectory(string path)

Full path of the directory to create.

None.

Terminal window
$cs.File_CreateDirectory("${env:ProgramFiles(x86)}\WinSCP")

Create a nested log folder before writing to it, since File_CreateDirectory also creates any missing parent folders in one call:

Terminal window
$LogFolder = "$env:ProgramData\Contoso\App\Logs\2026"
$cs.File_CreateDirectory($LogFolder)
$cs.File_AppendToFile((Join-Path $LogFolder "install.log"), "Install started")

Because it’s a no-op when the folder already exists, it’s safe to call unconditionally at the start of Install to guarantee a data folder is present:

Terminal window
$DataFolder = Join-Path $env:ProgramData "Contoso\App\Data"
$cs.File_CreateDirectory($DataFolder)

$cs.File_ExistDir $cs.File_DelTree