public void TestLongPathSupport() { string uncPath = "\\\\serverxx\\directory"; string uncPathLong = UtilsSystem.AddLongPathSupport(uncPath); Assert.Equal("\\\\?\\UNC\\serverxx\\directory", uncPathLong); Assert.Equal(uncPath, UtilsSystem.RemoveLongPathSupport(uncPathLong)); Assert.Equal(uncPath, UtilsSystem.RemoveLongPathSupport(uncPath)); string regularPath = "c:\\windows\\temp"; string regularPathLong = UtilsSystem.AddLongPathSupport(regularPath); Assert.Equal("\\\\?\\c:\\windows\\temp", regularPathLong); Assert.Equal(regularPath, UtilsSystem.RemoveLongPathSupport(regularPathLong)); Assert.Equal(regularPath, UtilsSystem.RemoveLongPathSupport(regularPath)); // Create a very long filename, individual segments can't be over 255 characters string fileName = "c:\\"; for (int x = 0; x < 100; x++) { fileName += Guid.NewGuid() + "\\"; } Assert.ThrowsAny <Exception>(() => { Directory.CreateDirectory(fileName); }); var fileNameWithLongPathSupport = UtilsSystem.EnsureLongPathSupportIfAvailable(fileName); Directory.CreateDirectory(fileNameWithLongPathSupport); fileNameWithLongPathSupport += "info.txt"; File.WriteAllText(fileNameWithLongPathSupport, "empty contents"); File.Delete(fileNameWithLongPathSupport); }