2012-10-11

How to create files with a leading period in the filename with Microsoft Explorer

I have to post this, because this seems a very frequently asked question on the internet, and while there is a straight-forward solution, most people propose bizarre solutions that circumvent the problem by using some other tool.

If you dig deeper, you'll find working solutions in comments, but they're incomplete and its not obvious at first that it even works.

The Problem


The problem is simple: You wish to create a unix-style hidden file, such as ".htaccess" , ".gitignore", or ".netrc", or a unix-style hidden folder, for whatever reason.

While this is not a problem for literally any tool other than Windows Explorer, attempting to do this in Explorer yields the following error:

You must type a file name.
The Windows Explorer "Rename" Dialog showing the error "You must type a file name."

The Solution

Most proponents suggest strange solutions such as using cmd.exe or notepad to do your dirty work,  and even Microsoft Developers seem to think that letting Explorer do this is crazy and suggest using some other tool

However, all that is unnecessary.

All that is required is writing an additional dot ( period ) at the tailing end.

If you wanted '.htaccess', instead, write '.htaccess.'
If you wanted '.gitignore' , instead, write '.gitignore.'

Explorer will silently strip the last dot and give you the file name you wanted, with no fuss.

The Windows Explorer Rename Dialog showing the error "You must type a file name." as a result of the user specifying ".gitignore" as the file name

Windows Explorer prompting the user to confirm they want to change a file name extension, as a result of specifying the filename as ".gitignore."

Windows Explorer showing the successfully renamed file as ".gitignore" after confirming the file extension change, showing how the trailing period has been removed


1 comment: