• Windows的文件类型关联


    在用脚本语言开发时尤其是在windows环境下发现想自动在命令行环境下运行脚本必须要带着相应的解释器的路径才行,不然就会提示无法找到对应的命令,于是乎在《学习Ruby》这本书中对于文件类型关联的方法有所介绍,其方法主要是采用了assoc和ftype两个命令来建立文件关联的。实际上其他脚本语言例如perl、tcl、python也是如此。

    以Ruby语言为例,具体做法如下:

    在命令行下输入如下命令:C:/Documents and Settings/Stanley>assoc .rb=rbFile

    接着测试文件关联是否成立:C:/Documents and Settings/Stanley>assoc .rb
                                                                                                                         .rb=rbFile

    接着测试文件类型是否存在:C:/Documents and Settings/Stanley>ftype rbfile
                                                                                                                          rbfile="c:/ruby/bin/ruby.exe" "%1" %*

    如果不存在可以手动建立:C:/Documents and Settings/Stanley>ftype rbfile=  "c:/ruby/bin/ruby.exe" "%1" %*

    最后把.rb加入环境变量PATHEXT,先检查看看:

    C:/Documents and Settings/Stanley>set pathext
    PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

    如果没有看到.rb就动手将它加进去:C:/Documents and Settings/Stanley>set pathext=.rb;%pathext%

    然后再次测试:

    C:/Documents and Settings/Stanley>set pathext
    PATHEXT=.rb;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

    查看关联
    assoc .wei
    设置关联
    assoc .wei=weigefile

    查看具体关联
    ftype weigefile
    设置具体关联
    ftype weigefile="C:路径.exe" "%1" %*

    注册表UserChoice优先级最高

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts.tif]

    [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts.tifOpenWithList]
    "a"="DllHost.exe"
    "MRUList"="cbjiahgfe"
    "c"="WardTestTIF.exe"
    "d"="STDUViewerApp.exe"
    "f"="WINWORD.EXE"
    "g"="MSPVIEW.EXE"
    "h"="mspaint.exe"
    "j"="PDFEdit.exe"

    [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts.tifOpenWithProgids]
    "TIFImage.Document"=hex(0):
    "MSDI"=hex(0):
    "ward"=hex(0):

    [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts.tifUserChoice]
    "Progid"="Applications\WardTestTIF.exe"

  • 相关阅读:
    CentOS下安装Git
    MongoDB 从入门到精通专题教程
    mongodb分布式集群架构
    CentOS6.2 下安装中文语言包
    英语流利说 第18天
    英语流利说 第17天
    英语流利说 第16天
    英语流利说 第15天
    英语流利说 第14天
    英语流利说 第13天
  • 原文地址:https://www.cnblogs.com/lee2011/p/6340687.html
Copyright © 2020-2023  润新知