4

Why is it possible to create a file without a name i.e. .htaccess using notepad++, but when using windows explorer it requires a filename?

davejal
  • 553

2 Answers2

4

This has something to do with the way Microsoft allows Explorer.exe to work with saving files without a file name and just a file extension being specified.

It appears that some applications such as Notepad and Notepad++ do not have this limitation programmed into their logic, and they do allow saving files with just an extension—so this is a Windows Explorer security feature or function that enforces this not to occur by default at the program level.

enter image description here

WORKAROUND

A workaround is to add an extra dot at the end of the extension and Windows Explorer will allow it to be saved but it'll parse the trailing dot and save it without a file name and without the extra dot at the end.

So when you create it with Windows Explorer as .htaccess. it will not give the below error message, and allow you to save it just fine.

enter image description here

enter image description here

RESOURCE: How do I rename a file to .htaccess in Windows 7?

2

Technically, a file like .htaccess has a name of .htaccess and no extension. This follows from the official documentation of "Naming Files, Paths, and Namespaces" at https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx.

File and Directory Names

All file systems follow the same general naming conventions for an individual file: a base file name and an optional extension, separated by a period.

Note that there is always a name, what's optional is only the extension. So if the complete filename starts with a dot, and has no other dots in it, then that's the name and there is no extension. The language of the spec leaves no room for a filename to exist which has an extension but no name.

This can be verified by creating a couple of files named .htaccess and .htaccess.bak in an otherwise empty directory, then running the following at a cmd prompt.

C:\etc>dir /a-d /b *.*
.htaccess
.htaccess.bak

C:\etc>dir /a-d /b *. .htaccess

The first dir lists both files as expected, the second one (where *. matches files with no extension) lists .htaccess only.

As to Explorer, it seems to ignore the spec and follow its own rules. A file like .htaccess is displayed with both name = .htaccess and type = HTACCESS file as long as the extension is not registered. If the name matches a known extension then the name is left blank and the extension is considered to match e.g. a file .cmd is displayed with type = Windows Command Script and without a name (when using the default 'hide extensions for known file types' setting).

Since displaying a blank name looks bad, Explorer must have decided to block such names outright from being created by itself. That much transpares from http://blogs.msdn.com/b/oldnewthing/archive/2008/04/14/8389268.aspx.

dxiv
  • 2,073