Set and Limit file type association within the scope of a cmd shell

你。 提交于 2021-01-28 07:05:10

问题


On Windows, is there a way to create a cmd shell and set certain file type associations within it's scope and not affect system-wide file association. I'd like to launch a .bat file to open a shell with it's own defined file type association.... Something like this pseudo .bat file:

[my_shell.bat]
@echo off
~ASSOCIATE .jpg --> Google Image Viewer.exe
~ASSOCIATE .tga --> Adobe Photoshop
~ASSOCIATE .txt --> Komodo Edit
start cmd

And so, for example, any .txt file i'd open from the resulting shell would open in Komodo Edit, while double clicking a .txt file on my desktop would open it with whatever system-wide file association is defined, like notepad.


回答1:


That can be done with assoc and ftype

assoc .jpg=picture
ftype picture="C:\Program Files (x86)\IrfanView\i_view32.exe" "%1"

(note the output of assoc .jpg and ftype WhateverYouUseAsName before so that you are able to revert it, if needed)




回答2:


This doesn't solve the problem entirely and requires some system wide modifications but at least you can get local scope associations. You can do this by associating the file type to an environment variable and then modify the environment variable in the current cmd scope.

We had the same issue for python files and solved it like this. So first set the file assocation to a variable path.

ftype Python.File=%PYTHON%\python.exe "%1" %*

and then in the local cmd scope you set the environment variable to the appropriate value.

set PYTHON=C:\Python27\2.7.9


来源:https://stackoverflow.com/questions/21943629/set-and-limit-file-type-association-within-the-scope-of-a-cmd-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!