7

In CMD I get this:

C:\>assoc .css
.css=CSSfile

C:\>ftype CSSfile
File type 'CSSfile' not found or no open command associated with it.

But in explorer, CSS files have icon and I can double click and notepad is used to open it. Why does my Windows open CSS file with notepad?

I'm not asking HOW to open a file with certain program. I'm asking WHY .css file is associated with notepad, given "File type 'CSSfile' not found or no open command associated with it" ftype command tells.

Braiam
  • 4,749
Gqqnbig
  • 449

1 Answers1

7

Why does my Windows open CSS file with notepad?

Right click on the CSS file and click "Open With" > "Choose default program..."

You will see the the default program is set to "Notepad":

enter image description here

You can use this dialog to change the default application if you wish to do so.

In the registry the key HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.css has value PerceivedType set to text:

enter image description here

Warning:

  • Do not modify this entry. It is mentioned only to explain why Notepad is the default program.

Notepad is the default application for opening text files.

You can open the css file in a cmd shell by typing it's name and it will also open in notepad:

enter image description here


Why Notepad is the default application for opening text files?

If I have VIM, how do I make VIM the default application for extensions whose PerceivedType is text?

Notepad is registered as the command to be executed for files of perceived type text.

To change the command to vim edit the registry values described below and replace %SystemRoot%\system32\NOTEPAD.EXE with the path to vim.exe.

Registering a Perceived Type

Registry values for perceived types are defined as subkeys of the HKEY_CLASSES_ROOT\SystemFileAssociations registry subkey.

For example, the perceived type text is registered as follows:

HKEY_CLASSES_ROOT
   SystemFileAssociations
      text
         shell
            edit
               command
                  (Default) = "%SystemRoot%\system32\NOTEPAD.EXE" "%1"
            open
               command
                  (Default) = "%SystemRoot%\system32\NOTEPAD.EXE" "%1"

A file type's perceived type is indicated by including a PerceivedType value in the file type's subkey. The PerceivedType value is set to the name of the perceived type registered under HKEY_CLASSES_ROOT\SystemFileAssociations registry subkey, as shown in the previous registry example.

To declare .cpp files as being of perceived type "text", for example, add the following registry entry:

HKEY_CLASSES_ROOT
   .cpp
      PerceivedType = text

Source Application Registration

DavidPostill
  • 156,873
  • He wants to open with command line. And he can literally just right click to change the default program instead of manually changing the registry? – rassa45 May 18 '16 at 20:00
  • @ytpillai You can open from the command line. Read the answer carefully. – DavidPostill May 18 '16 at 20:01
  • @ytpillai Yes, you can change the default program (if you so wish) by right-clicking. – DavidPostill May 18 '16 at 20:02
  • Apologies I did not read carefully. Your answer is an interesting one where he does not need to write anything else. But why did you discredit mine? Doesn't my answer essentially do the same thing except with two more words? I don't want to discredit yours, only understand why I am wrong – rassa45 May 18 '16 at 20:03
  • Right, so isn't it better to use an easier solution (in response to your second comment). I think that registry may be a bit overboard and OP has a large chance of messing up his system if he is not experienced – rassa45 May 18 '16 at 20:04
  • @ytpillai The question is "Why does my Windows open CSS file with notepad?". Your answer did not explain why. – DavidPostill May 18 '16 at 20:05
  • @ytpillai The registry entry is only there to explain the why. He did not ask how to change anything and I did not suggest modifying the registry. I will add a warning to the answer just in case. – DavidPostill May 18 '16 at 20:06
  • In a way aren't we both saying the same thing except you go more in detail – rassa45 May 18 '16 at 20:07
  • @ytpillai Only because you changed your answer after my comment. – DavidPostill May 18 '16 at 20:11
  • Thank you for the advice. Yes I did take it. Do I still deserve a down vote – rassa45 May 18 '16 at 20:12
  • Downvote and initial comment removed. – DavidPostill May 18 '16 at 20:12
  • At ease, I'm not novice. The most valuable part in your answer is "Notepad is the default application for opening text files." So the question is why Notepad is the default application for opening text files? If I have VIM, how do I make VIM the default application for extensions whose PerceivedType is text? – Gqqnbig May 18 '16 at 21:33
  • 1
    @LoveRight I'm in a good mood so I will answer your new question. See the updated answer. – DavidPostill May 18 '16 at 21:45
  • Excellent! I assume if HKEY_CLASSES_ROOT\CSSfile has shell\open key, it will override the one specified in perceived type. Am I right? – Gqqnbig May 18 '16 at 22:00
  • @LoveRight I believe so. I haven't tested it. – DavidPostill May 18 '16 at 22:08