The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
DirectoryInfo::Create Method ()
.NET Framework (current version)
Creates a directory.
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| IOException | The directory cannot be created. |
If the directory already exists, this method does nothing.
For a list of common I/O tasks, see Common I-O Tasks.
The following example checks whether a specified directory exists, creates the directory if it does not exist, and deletes the directory.
using namespace System; using namespace System::IO; int main() { // Specify the directories you want to manipulate. DirectoryInfo^ di = gcnew DirectoryInfo( "c:\\MyDir" ); try { // Determine whether the directory exists. if ( di->Exists ) { // Indicate that it already exists. Console::WriteLine( "That path exists already." ); return 0; } // Try to create the directory. di->Create(); Console::WriteLine( "The directory was created successfully." ); // Delete the directory. di->Delete(); Console::WriteLine( "The directory was deleted successfully." ); } catch ( Exception^ e ) { Console::WriteLine( "The process failed: {0}", e ); } }
FileIOPermission
for writing files. Associated enumeration: FileIOPermissionAccess::Write
Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Show: