在cmd shell范围内设置和限制文件类型关联 [英] Set and Limit file type association within the scope of a cmd shell

查看:46
本文介绍了在cmd shell范围内设置和限制文件类型关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上,有一种方法可以创建cmd shell并在其作用域内设置某些文件类型关联,而不会影响系统范围的文件关联.我想启动一个.bat文件以使用其自己定义的文件类型关联来打开外壳....类似此伪.bat文件的东西:

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

因此,例如,我从生成的外壳中打开的任何.txt文件都将在Komodo Edit中打开,而双击桌面上的.txt文件将使用定义的系统范围的文件关联将其打开,就像记事本一样.

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.

推荐答案

这不能完全解决问题,需要对系统进行一些修改,但至少可以获取本地范围关联.您可以通过将文件类型与环境变量关联,然后在当前cmd范围内修改环境变量来实现此目的.

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.

对于python文件,我们遇到了同样的问题,并像这样解决了它.因此,首先将文件关联设置为可变路径.

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" %*

,然后在本地cmd范围内将环境变量设置为适当的值.

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

set PYTHON=C:\Python27\2.7.9

这篇关于在cmd shell范围内设置和限制文件类型关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆