How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess

Windows.HtaccessWindows XpFilenames

Windows Problem Overview


I want to create a .htaccess file manually and discovered it seems impossible through the Windows UI. I get a "you must type a filename." message. There has to be a way to create files with . as a prefix in Windows.

Can this be done manually?

Enter image description here

Windows Solutions


Solution 1 - Windows

If you start Notepad and then File -> Save As -> Write .htaccess and choose "All Files" as the type - then it will create the .htaccess file for you.

Notepad save as .htaccess

Solution 2 - Windows

Windows 7, 8 & 10

This is dead easy since Windows 7. In File Explorer, right click anywhere and create a new file. Type the new filename as .something. (notice the appended period) and press enter twice, job done.

Demonstrating how to create a file with no name in File Explorer.

So instead of being prompted with

> You must type a file name.

You will instead be prompted with

> If you change a file name extension, the file might become unusable.

Note: If you're having issues then please ensure you have "file name extensions" visible, you can activate this under the "View" menu in File Explorer. Also, this method works for folders too.

Solution 3 - Windows

Within Notepad select File > Save As...

File name: ".whatever you want" (with the leading dot)

You can do it in Explorer (in Windows 7) by adding a period at the end of the filename:

.whatever you want.

Windows will automatically remove the trailing dot when you validate.

Solution 4 - Windows

Go to command prompt, cd to the appropriate folder and type:

notepad .htaccess

After confirmation dialog the file will be created and you will be editing it directly. If you just want to create an empty file, try

echo. > .htaccess

Solution 5 - Windows

You could also use Command Prompt with move: move x.extension .extension

Solution 6 - Windows

You can do this in any program other than Explorer, e.g. Notepad, cmd.exe etc.

You just can't do it in Explorer, and Raymond Chen has offered an explanation as to why not.

Solution 7 - Windows

Just type .htaccess. as filename. Notice the dot at the end of htaccess. This will change in Windows to .htaccess without a dot at the end.

Solution 8 - Windows

You can save it using the Save As dialog using ".something".

Solution 9 - Windows

Even if you don't have any third party editor (Notepad++ etc.) then also you can create files with dot as prefix.

To create .htaccess file, first create htaccess.txt file with Context Menu > New Text Document.

Then press Alt + D (Windows 7) and Ctrl + C to copy the path from the Address bar of Windows Explorer.

Then go to command line and type code as below to rename your file:

rename C:\path\to\htaccess.txt .htaccess

Now you have a blank .htaccess without opening it in any editor.

Hope this helps you out.

Solution 10 - Windows

Use something like Notepad++ (or even Notepad), 'Save As', and enter the name .htaccess that way. I always found it weird, but it lets you do it from a program!

Solution 11 - Windows

Might sound unbelivable, but Windows 1903 finally allows to name files in Explorer with a leading dot :-)

Solution 12 - Windows

In Windows, just go to the folder using cmd and type the following command:

DIR>.htaccess

This command will create a .htaccess file and will dump some data in it. Remove the data, and it can be used as .htaccess file.

Solution 13 - Windows

It seems that Microsoft finally is addressing this problem. Current versions in the Insider Editions of Explorer allows creating files with a dot at the front.

Tested with Build 19541

Solution 14 - Windows

As an addition, if have Sublime Text installed in your development computer, you can drag the file to your opened Sublime Text window, right click the filename -> rename and enter whatever name even without any extension. This worked for me.

Solution 15 - Windows

If you use Git and have Git Bash installed you can open a Git Bash at the directory (via Right Click in the white space in Explorer > Git Bash Here) and do:

touch .htaccess

Solution 16 - Windows

You can use echo. > .gitignore. This is how I achieved it to create .gitignore:

C:\Users\jaimemontoya\[path]>dir
 Volume in drive C is OS
 Volume Serial Number is 2BD2-JQ68

 Directory of C:\Users\jaimejaimemontoya\[path]

11/02/2021  02:42 AM    <DIR>          .
11/02/2021  02:42 AM    <DIR>          ..
11/05/2021  05:22 AM    <DIR>          .git
11/02/2021  02:41 AM    <DIR>          .gradle
11/02/2021  02:43 AM    <DIR>          .idea
11/02/2021  02:41 AM    <DIR>          app
11/02/2021  02:41 AM    <DIR>          build
..........
..........
              12 File(s)         14,104 bytes
               8 Dir(s)  231,501,361,152 bytes free
			   
C:\Users\jaimemontoya\[path]>echo. > .gitignore

C:\Users\jaimemontoya\[path]>dir
 Volume in drive C is OS
 Volume Serial Number is 2BD2-JQ68

 Directory of C:\Users\jaimemontoya\[path]

11/05/2021  05:40 AM    <DIR>          .
11/05/2021  05:40 AM    <DIR>          ..
11/05/2021  05:22 AM    <DIR>          .git
11/05/2021  05:40 AM                 3 .gitignore
11/02/2021  02:41 AM    <DIR>          .gradle
11/02/2021  02:43 AM    <DIR>          .idea
11/02/2021  02:41 AM    <DIR>          app
11/02/2021  02:41 AM    <DIR>          build
..........
..........    
              13 File(s)         14,107 bytes
               8 Dir(s)  231,512,551,424 bytes free	

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDoug ChamberlainView Question on Stackoverflow
Solution 1 - WindowsfoensView Answer on Stackoverflow
Solution 2 - WindowsMatt KieranView Answer on Stackoverflow
Solution 3 - WindowsdhirschlView Answer on Stackoverflow
Solution 4 - WindowsBoockoView Answer on Stackoverflow
Solution 5 - WindowsNikoloffView Answer on Stackoverflow
Solution 6 - WindowsDavid HeffernanView Answer on Stackoverflow
Solution 7 - WindowsJackyView Answer on Stackoverflow
Solution 8 - WindowsSachin ShanbhagView Answer on Stackoverflow
Solution 9 - WindowsVicky DevView Answer on Stackoverflow
Solution 10 - WindowsBrianView Answer on Stackoverflow
Solution 11 - WindowsdebuglevelView Answer on Stackoverflow
Solution 12 - WindowsEugine JosephView Answer on Stackoverflow
Solution 13 - Windowstheking2View Answer on Stackoverflow
Solution 14 - WindowsDiego PoncianoView Answer on Stackoverflow
Solution 15 - WindowsgpreslandView Answer on Stackoverflow
Solution 16 - WindowsJaime MontoyaView Answer on Stackoverflow