Create directory if it does not exist

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Create directory if it does not exist

Message par ForumBot »

Create directory if it does not exist
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Create directory if it does not exist

Message par ForumBot »

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 »