0

When I give the path of a .py file to cmd.exe , It run that file automatically using Python.(I added the path of python to PATH Environment Variable already).

I want know:

1- how cmd.exe recognize that my .py file must run with python?

2- If I want to remove .py from the end of my file name, And replace it with .wxyz (for example), How I can make cmd.exe behave with that file such as a .py file? (In the other word I mean I want to add .wxyz extension to the list of files that run with python)

Ahmed Fasih
  • 6,458
  • 7
  • 54
  • 95
TheGoodUser
  • 1,188
  • 4
  • 26
  • 52
  • Possibly related: [What registry keys are responsible for file extension association?](http://social.msdn.microsoft.com/Forums/vstudio/en-US/630ed1d9-73f1-4cc0-bc84-04f29cffc13b/what-registry-keys-are-responsible-for-file-extension-association?forum=netfxbcl) (off-site resource) – Kevin Sep 05 '14 at 16:10

2 Answers2

2

Windows keeps a list of file extensions and the programs that should run them. You can see the current list and add your own by going to the control panel, searching for "Default Programs" and selecting the entry that says something like "Make a file type always open in a specific program" (it varies by windows version and language of course).

Alternately, you can do it on the command line with the assoc and ftype commands. I don't have a windows machine up at the moment, but type these and see what you get.

assoc .py
ftype File.Python

This will get you the help on how to change them

assoc /?
ftype /?
tdelaney
  • 73,364
  • 6
  • 83
  • 116
1

1) There is a good explanation here:

When the Shell needs to query for the file associations of a file type, it creates an array of registry keys containing the associations for the file type, and checks these keys for the appropriate file associations to use.

In short, when you installed Python, it equipped Windows with enough context to know it should call for Python when it sees .py

2) A concise explanation is found here, with more context here.

In Windows this can be accomplished by editing the registry, allowing Windows to recognize custom extensions.

Community
  • 1
  • 1
Aphid
  • 343
  • 1
  • 9