Skip to content

Instantly share code, notes, and snippets.

@CyberShadow
Last active September 20, 2018 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CyberShadow/049cf06f4ec31b205dde4b0e3c12a986 to your computer and use it in GitHub Desktop.
Save CyberShadow/049cf06f4ec31b205dde4b0e3c12a986 to your computer and use it in GitHub Desktop.
Windows path limitation tests
*.exe
*.pdb
*.ilk
// Warning: this program creates and deletes files and directories on C:\.
// Run at your own risk! (Better use a VM)
import std.array;
import std.file;
import std.range;
import std.stdio;
import ae.sys.file : longPath;
void main()
{
for (int chars = 1; ; chars++)
{
auto path = `C:\` ~ replicate("a", chars);
if (path.longPath.exists) path.longPath.rmdirRecurse();
scope(exit) if (path.longPath.exists) path.longPath.rmdirRecurse();
try
mkdir(path);
catch (Exception e)
{
writefln("mkdir (%d chars) absolute limit: %s chars: %s", chars, path.length, e.msg.replace(path, "[path]"));
break;
}
}
foreach (chars; 1..3+1)
{
auto root = (`C:\` ~ replicate("a", chars)).longPath;
if (root.exists) root.rmdirRecurse;
scope(exit) root.rmdirRecurse();
for (int n = 1; ; n++)
{
auto path = `C:\` ~ replicate(replicate("a", chars) ~ `\`, n);
try
mkdir(path);
catch (Exception e)
{
writefln("nested mkdir (%d chars) absolute limit: %s chars (%d dirs): %s", chars, path.length, n, e.msg.replace(path, "[path]"));
break;
}
}
}
foreach (chars; 1..3+1)
{
auto root = (`C:\` ~ replicate("a", chars)).longPath;
if (root.exists) root.rmdirRecurse;
scope(exit) root.rmdirRecurse();
chdir(`C:\`);
scope(exit) chdir(`C:\`);
for (int n = 0; ; n++)
{
auto path = replicate("a", chars);
string op;
try
{
op = "mkdir"; mkdir(path);
op = "chdir"; chdir(path);
}
catch (Exception e)
{
writefln("descending mkdir (%d chars) absolute limit (%s): %s chars (%d dirs): %s", chars, op, path.length, n, e.msg);
break;
}
}
}
foreach (chars; 1..3+1)
{
auto dir = replicate("a", chars);
auto root = (`C:\` ~ dir).longPath;
if (root.exists) root.rmdirRecurse;
scope(exit) root.rmdirRecurse();
// Make arena
mkdirRecurse(longPath(`C:\` ~ replicate(dir ~ `\`, 1000)));
writeln;
enum step = 10;
foreach (start; iota(0, 300, step))
{
auto cwd = `C:\` ~ replicate(dir ~ `\`, start);
try
chdir(cwd);
catch (Exception e)
continue;
scope(exit) chdir(`C:\`);
writef("relative write (%d chars, CWD at %s dirs / %d chars):", chars, start, cwd.length);
foreach (back; iota(0, start+1, step))
{
bool found;
foreach (forward; iota(0, 300, step))
{
auto path = replicate(`..\`, back) ~ replicate(dir ~ `\`, forward) ~ `f`;
try
std.file.write(path, "");
catch (Exception e)
{
writef(" -%d+%d", back, forward);
found = true;
break;
}
}
if (!found)
writef(" -%d+∞", back);
}
writeln;
}
}
}
mkdir (245 chars) absolute limit: 248 chars: [path]: The filename or extension is too long. (error 206)
nested mkdir (1 chars) absolute limit: 249 chars (123 dirs): [path]: The filename or extension is too long. (error 206)
nested mkdir (2 chars) absolute limit: 249 chars (82 dirs): [path]: The filename or extension is too long. (error 206)
nested mkdir (3 chars) absolute limit: 251 chars (62 dirs): [path]: The filename or extension is too long. (error 206)
descending mkdir (1 chars) absolute limit (mkdir): 1 chars (122 dirs): a: The filename or extension is too long. (error 206)
descending mkdir (2 chars) absolute limit (mkdir): 2 chars (81 dirs): aa: The filename or extension is too long. (error 206)
descending mkdir (3 chars) absolute limit (mkdir): 3 chars (61 dirs): aaa: The filename or extension is too long. (error 206)
relative write (1 chars, CWD at 0 dirs / 3 chars): -0+0
relative write (1 chars, CWD at 10 dirs / 23 chars): -0+120 -10+0
relative write (1 chars, CWD at 20 dirs / 43 chars): -0+110 -10+100 -20+0
relative write (1 chars, CWD at 30 dirs / 63 chars): -0+100 -10+90 -20+70 -30+0
relative write (1 chars, CWD at 40 dirs / 83 chars): -0+90 -10+80 -20+60 -30+50 -40+0
relative write (1 chars, CWD at 50 dirs / 103 chars): -0+80 -10+70 -20+50 -30+40 -40+20 -50+0
relative write (1 chars, CWD at 60 dirs / 123 chars): -0+70 -10+60 -20+40 -30+30 -40+10 -50+0 -60+0
relative write (1 chars, CWD at 70 dirs / 143 chars): -0+60 -10+50 -20+30 -30+20 -40+0 -50+0 -60+0 -70+0
relative write (1 chars, CWD at 80 dirs / 163 chars): -0+50 -10+40 -20+20 -30+10 -40+0 -50+0 -60+0 -70+0 -80+0
relative write (1 chars, CWD at 90 dirs / 183 chars): -0+40 -10+30 -20+10 -30+0 -40+0 -50+0 -60+0 -70+0 -80+0 -90+0
relative write (1 chars, CWD at 100 dirs / 203 chars): -0+30 -10+20 -20+0 -30+0 -40+0 -50+0 -60+0 -70+0 -80+0 -90+0 -100+0
relative write (1 chars, CWD at 110 dirs / 223 chars): -0+20 -10+10 -20+0 -30+0 -40+0 -50+0 -60+0 -70+0 -80+0 -90+0 -100+0 -110+0
relative write (1 chars, CWD at 120 dirs / 243 chars): -0+10 -10+0 -20+0 -30+0 -40+0 -50+0 -60+0 -70+0 -80+0 -90+0 -100+0 -110+0 -120+0
relative write (2 chars, CWD at 0 dirs / 3 chars): -0+0
relative write (2 chars, CWD at 10 dirs / 33 chars): -0+80 -10+0
relative write (2 chars, CWD at 20 dirs / 63 chars): -0+70 -10+60 -20+0
relative write (2 chars, CWD at 30 dirs / 93 chars): -0+60 -10+50 -20+40 -30+0
relative write (2 chars, CWD at 40 dirs / 123 chars): -0+50 -10+40 -20+30 -30+20 -40+0
relative write (2 chars, CWD at 50 dirs / 153 chars): -0+40 -10+30 -20+20 -30+10 -40+0 -50+0
relative write (2 chars, CWD at 60 dirs / 183 chars): -0+30 -10+20 -20+10 -30+0 -40+0 -50+0 -60+0
relative write (2 chars, CWD at 70 dirs / 213 chars): -0+20 -10+10 -20+0 -30+0 -40+0 -50+0 -60+0 -70+0
relative write (2 chars, CWD at 80 dirs / 243 chars): -0+10 -10+0 -20+0 -30+0 -40+0 -50+0 -60+0 -70+0 -80+0
relative write (3 chars, CWD at 0 dirs / 3 chars): -0+0
relative write (3 chars, CWD at 10 dirs / 43 chars): -0+60 -10+0
relative write (3 chars, CWD at 20 dirs / 83 chars): -0+50 -10+40 -20+0
relative write (3 chars, CWD at 30 dirs / 123 chars): -0+40 -10+30 -20+20 -30+0
relative write (3 chars, CWD at 40 dirs / 163 chars): -0+30 -10+20 -20+10 -30+10 -40+0
relative write (3 chars, CWD at 50 dirs / 203 chars): -0+20 -10+10 -20+0 -30+0 -40+0 -50+0
relative write (3 chars, CWD at 60 dirs / 243 chars): -0+10 -10+0 -20+0 -30+0 -40+0 -50+0 -60+0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment