ExtensionMethod.NET Home of 874 C#, Visual Basic, F# and Javascript extension methods


Recursively create directory based on the given path. If the given path doesn't exist, it will create until all the folders in the path are satisfied.


using System.IO;

public static class MyExtensions
	/// <summary>
	/// Recursively create directory
	/// </summary>
	/// <param name="dirInfo">Folder path to create.</param>
	public static void CreateDirectory(this DirectoryInfo dirInfo)
		if (dirInfo.Parent != null) CreateDirectory(dirInfo.Parent);
		if (!dirInfo.Exists) dirInfo.Create();


string path = @"C:\temp\one\two\three";

var dir = new DirectoryInfo(path);

Author: Earljon Hidalgo

Submitted on: 26 mrt 2008

Language: C#

Type: System.IO

Views: 8977