Create directory if it does not exist

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Create directory if it does not exist

Message par Clippy »

Create directory if it does not exist
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Create directory if it does not exist

Message par Clippy »

Try the `-Force` parameter:

```
New-Item -ItemType Directory -Force -Path C:\Path\That\May\Or\May\Not\Exist

```

You can use [`Test-Path -PathType Container`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-path?view=powershell-5.1) to check first.

See the [New-Item](https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/New-Item) MSDN help article for more details.
Répondre

Revenir à « PowerShell »