Why folder or file name in Windows cannot end with space?

5,388

From Microsoft Naming Files, Paths, and Namespaces article:

Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".

Share:
5,388

Related videos on Youtube

Pol
Author by

Pol

Updated on September 18, 2022

Comments

  • Pol
    Pol over 1 year

    I learned something new today. When I tried create new folder "folder " (no quotes) in Visual Studio I got error:

    Directory names cannot contain any of the following characters:

    : * ? | " < >

    But my folder name doesn't have any of those characters. So I tried creating this folder in Windows explorer and it strips space from end and creates folder "folder" instead of "folder ". Same does md command and same goes for file names. Why folder or file name in Windows cannot end with space?

    I tried this on NTFS partition (Windows 8.1).

    • Brian Warshaw
      Brian Warshaw about 10 years
      If you're just asking theoretically, very well. If not, why would you want to end a filename with a space?
    • Pol
      Pol about 10 years
      I'm asking theoretically.
    • harrymc
      harrymc almost 10 years
      What does Visual Studio have to do with creating folders?
  • Pol
    Pol about 10 years
    If anyone knows why "Windows shell and user interface does not support such names" that would be even better answer.
  • Ramhound
    Ramhound about 10 years
    @Pol - "Why" would be outside of the purview of this website.
  • Pol
    Pol about 10 years
    @Ramhound - Why = technical or UI reasons = scope of this website, I guess. If not, what other Stack Exchange site would suit better? I'm assuming this wasn't irony. Cheers.
  • Ramhound
    Ramhound about 10 years
    @Pol - Because "why" is a broad question. "Why" can only be answered by Microsoft which won't happen. The technical reasons are public hence this answer. Besides it can actually be used....its just not supported by Windows Explorer or the shell. If both were replaced you could
  • Pol
    Pol about 10 years
    @Ramhound - CreateFileA from kernel32.dll (not a shell part) doesn't allow creating (opening) two files whose name is different only by space at the end. Have a good day.