开发者

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

I want to create a .htaccess file manually and discovered it see开发者_如何学编程ms 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?

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


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.

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


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.

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

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.


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.


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


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


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.


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.


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.


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


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!


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


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.


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


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


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.


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 


in windows, you can also use cmd to create these type of file.

  1. run cmd
  2. goto directory where you want to create this folder
  3. type mkdir .htacess

Please verify if this file is created or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜