5

On Linux, I can have a folder named temp..

If I try to do a mkdir temp. on a Windows machine, the trailing period is truncated.

If I try to sync a directory from Linux to Windows that has a trailing period, it will fail (found in seafile by a colleague).

Why is that?

phuclv
  • 26,555
  • 15
  • 113
  • 235
warren
  • 9,920
  • 23
  • 86
  • 147
  • 1
    So are you asking why NTFS doesn't allow it, why Seafile doesn't handle it gracefully, or how to Sync a file from Linux to Windows that has a period on the end? We need clarification, as questions like "why is this like this?" are generally considered "Not Constructive" and will be closed. Please consider editing your question to make it more about a specific problem you're trying to solve. – Ƭᴇcʜιᴇ007 Apr 19 '13 at 19:20
  • 1
    Though this likely won't solve your problem, if you lead the path name with \\?\ you should be able to name the folder as you wish. You should be able to run something along the lines of "mkdir \\?\C:\temp." in cmd and have it make a folder called "temp." under C:\, but you won't be able to access it since "?" isn't a network location. That said, you *might* be able to try that with a real network place and have it work, but I'm unable to test that in my current environment. – Mono Apr 19 '13 at 19:26
  • 3
    NTFS does not disallow it, just the Win32 API does. As Alex noted, if you use `\\?\...` to skip the usual parsing and give the raw path to the NT API, then you *can* create a directory with a trailing period. – u1686_grawity Apr 19 '13 at 19:44
  • @grawity that should be an answer, as its what I almost answered – Austin T French Apr 19 '13 at 19:46
  • @AthomSfere: It doesn't answer why Microsoft made the decision to strip the trailing period. On the second thought... – u1686_grawity Apr 19 '13 at 20:09
  • 1
    @Alex: By the way, the period is stripped locally – the Windows SMB server [talks directly](http://blogs.msdn.com/b/oldnewthing/archive/2006/12/05/1211409.aspx#1264232) to the NT API and allows creation of any name. – u1686_grawity Apr 19 '13 at 20:21
  • @grawity but it does clarify that the issue is not NTFS. Also as you said, we will never likely know exactly why, unless old engineers from MS decide to respond – Austin T French Apr 19 '13 at 20:58
  • @techie007 - I'm asking why NTFS disallows trailing periods. How I found out about it is merely for background: I don't care how to fix Seafile at the moment, as I'm not a developer. – warren Apr 22 '13 at 13:57
  • duplicate: [Why isn't it possible to name a folder "._." in Windows 7?](https://superuser.com/q/1028139/241386), [Dots at the end of file name?](https://superuser.com/q/230385/241386) – phuclv Oct 06 '21 at 15:17

1 Answers1

9

NTFS does not disallow it, it's only the Win32 API that does. As Alex noted in a comment, if you use \\?\... to skip the usual parsing and give the raw path to the NT API, then you can create a directory with a trailing period.

(Why does this work? The article Win32 File Namespaces says: "For file I/O, the "\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs.")

As for why the trailing period is stripped, there doesn't seem to be any official documentation, but it might have to do something with compatibility with old MS-DOS or Windows 3.11 programs. In the 8.3 filename world, an empty extension and no extension at all was the same thing – in both cases, the filename XYZ would have been stored as XYZ····· and the extension as ··· (dots representing null bytes), so there might have been programs that relied on this fact. When Windows 95 got long filename support, it started storing both the name and extension as a single string, causing xyz and xyz. to become different filenames. It probably had to strip the trailing period to avoid breaking such programs.

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966