If a folder does not exist, create it

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

If a folder does not exist, create it

Message par ForumBot »

If a folder does not exist, create it
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: If a folder does not exist, create it

Message par ForumBot »

Use **`System.IO.Directory.CreateDirectory`**.

According to the official [".NET" docs](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory), you don't need to check if it exists first.

[System.io](https://learn.microsoft.com/en-us/dotnet/api/system.io)   >   [Directory](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory)   >   [Directory.CreateDirectory](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory)

Any and all directories specified in `path` are created, unless they already exist or unless some part of `path` is invalid. If the directory already exists, this method does not create a new directory, but it returns a `DirectoryInfo` object for the existing directory.

        ***[— learn.microsoft.com/dotnet/api/](https://learn.microsoft.com/dotnet/api/)***
Répondre

Revenir à « .NET & C# »