Skip to content

Instantly share code, notes, and snippets.



Last active May 11, 2016
What would you like to do?

Maxpath and .NET

Changes to .NET Core now allow for longer paths for directories. Here's a sample showcasing that.

Note: this sample is running on .NET Core. The easiest way to get going with that is to get the bits, create these files in a directory, and open that directory with Visual Studio Code.

To build and run:

$ dnu restore
$ dnu build
$ dnx run


This contains the NuGet dependencies needed to run the sample.

	"dependencies": {
		"System.Console": "4.0.0-beta-23516",
	"frameworks": {


Here's the sample!

using System;
using System.IO;

namespace MaxPath
	public class Program
		public void Main(string[] args)
			// Paths can now be created/manipulated over the legacy 260 character limit.
			// On Windows, the max length is now ~32k!
			// .NET used to only be able to create directories 248 characters deep.
			// This made 254 characters impossible even if the total length was under 260.
			var directory = Directory.CreateDirectory(
			                    new string('d', 254)));
			// The max segment length on Windows is 255, so let's do that!
			// Note: UDF still requires 254 (optical media uses 254)
			string path = Path.Combine(directory.FullName, new string('f', 254));
			File.WriteAllText(path, "Really long paths!");
			Console.WriteLine($"Path length is: {path.Length}");
			directory.Delete(recursive: true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment