UweKeim / ZetaLongPaths

A .NET library to access files and directories with more than 260 characters length.
https://nuget.org/packages/ZetaLongPaths
MIT License
141 stars 28 forks source link

ZlpDirectoryInfo.Name is empty when dir path has trailing slash #15

Closed DizzyHSlightlyVoided closed 7 years ago

DizzyHSlightlyVoided commented 7 years ago

As the title says:

ZlpDirectoryInfo dirInfo1 = new ZlpDirectoryInfo(@"C:\Foo\Bar");
Console.WriteLine(dirInfo1.Name); //"Bar"
ZlpDirectoryInfo dirInfo2 = new ZlpDirectoryInfo(@"C:\Foo\Bar\");
Console.WriteLine(dirInfo2.Name); //"", an empty string
UweKeim commented 7 years ago

I've just did a test:

var dirInfo1 = new ZlpDirectoryInfo(@"C:\Foo\Bar");
Console.WriteLine(dirInfo1.Name); //"Bar"
var dirInfo2 = new ZlpDirectoryInfo(@"C:\Foo\Bar\");
Console.WriteLine(dirInfo2.Name); //"", an empty string

var dirInfo3 = new DirectoryInfo(@"C:\Foo\Bar");
Console.WriteLine(dirInfo1.Name);
var dirInfo4 = new DirectoryInfo(@"C:\Foo\Bar\");
Console.WriteLine(dirInfo2.Name);

if( dirInfo1.FullName!=dirInfo3.FullName) throw new Exception(@"1-3");
if( dirInfo2.FullName!=dirInfo4.FullName) throw new Exception(@"2-4");

In my tests, the ZlpDirectoryInfo classes resulted in the same strings as those DirectoryInfo classes.

DizzyHSlightlyVoided commented 7 years ago

One sec while I try this with the exact path that was causing the issue ...

It seems to have something to do with the length. Or something. I got the effect when I used D:\SomeStuff\Name Space\More.Stuff\Test

This is on the latest NuGet release, by the way, 1.0.0.16

UweKeim commented 7 years ago

Sorry, my above tests are flawed. I'll can see the different behavior now.

Old, wrong tests:

if( dirInfo1.FullName!=dirInfo3.FullName) throw new Exception(@"1-3");
if( dirInfo2.FullName!=dirInfo4.FullName) throw new Exception(@"2-4");

New correct tests:

if( dirInfo1.Name!=dirInfo3.Name) throw new Exception(@"1-3");
if( dirInfo2.Name!=dirInfo4.Name) throw new Exception(@"2-4");

I'll fix this right now.

UweKeim commented 7 years ago

I've just updated the NuGet package und this GitHub repository.