Windows tip: create files with just a file extension

Posted: (EET/GMT+2)

 

Sometimes, you need to create files that have filenames that start with the period (dot), and only contain a file extension. For instance, in Visual Studio Team Foundation Version Control (TFVC from TFS) you can create a file called ".tfignore" to your solution folder to have certain files and folder excluded from version control.

However, if you use Windows' graphical user interface (File Explorer) to create files (right-clicking a folder, and then from the menu New -> Text Document), you cannot simply create a file that lacks the traditional filename, and only contains a file extension (i.e. the name starts with a period). Instead, you get the following error:

Rename
You must type a file name.

There are two solutions to this problem. First, you can create the file using File Explorer with a valid name, and then rename the file from the command-line. Or, you can go to the command-line and create the file from there.

Here's how: in File Explorer, create a file called "A.tfignore". Then, open the command prompt, and navigate to the correct folder. Type in the command "ren A.tfignore .tfignore" and press Enter.

Alternatively, go to the command-line, and type the command "copy con .tfignore" and press Enter. Then, press F6 key (or, Ctrl+Z), and your file is automatically generated.

Hope this helps!