peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

Bug in Pri.LongPath.Path.GetDirectoryName when filename contains dot + whitespace #32

Closed ngjermundshaug closed 8 years ago

ngjermundshaug commented 8 years ago

There is a bug in Pri.LongPath.Path.GetDirectoryName when the filename contains '. ' (dot and then whitespace).

System.IO.Path.GetDirectoryName("C:\\myfolder\\Con. approval.pdf")    // ==> C:\myfolder (correct)
Pri.LongPath.Path.GetDirectoryName("C:\\myfolder\\Con. approval.pdf") // ==> \\. (not correct)

Seems to be a win32 bug:

NativeMethods.GetFullPathName("C:\\myfolder\\Con. approval.pdf", (uint)buffer.Capacity, buffer, IntPtr.Zero) ==> buffer is set to \\.\Con - which is not correct

I have reported this here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364963(v=vs.85).aspx

peteraritchie commented 8 years ago

If it's a windows bug, there may not be much that can be done.

thomaslevesque commented 8 years ago

It's not because of the whitespace, it's because of the "con". "con" is a reserved filename (for the Console device), and a filename cannot include it as a whole word (of course something like "context" or "defcon" is fine). If you try to create a file named "Con. approval.pdf" or "con.pdf", it will fail.

ngjermundshaug commented 8 years ago

Awesome! Thanks for clearing this up Thomas!