dee*_*392 51 windows powershell batch file-association file-extension
我最近刚刚重新安装了 Windows,在设置我的环境时,我注意到我在 Notepad++ 中编辑的各种编程语言的所有关联(自然地)都消失了。
我在考虑未来,拥有某种批处理文件可以通过单击按钮自动将选择的文件扩展名与 N++ 相关联,而不是等到我遇到所有这些扩展名时,这不是很棒吗?经历导航到 N++ exe 等的繁琐。
我无法Default Programs
使用 Windows 7 附带的实用程序执行此操作,因为它仅适用于已“遇到”的扩展。
那么是否有可能以编程方式将文件扩展名与 Windows 上的应用程序相关联?
uSl*_*ckr 69
使用 Ftype & Assoc 来解决这个问题(它是可编写脚本的)。
使用 Assoc 获取文件类型
>Assoc .txt
Run Code Online (Sandbox Code Playgroud)
给你:
.txt = txt文件
然后
>Ftype txtfile=C:\Program Files (x86)\Notepad++\notepad++.exe %1
Run Code Online (Sandbox Code Playgroud)
一旦您知道文件类型,您就可以使用 Ftype 将其与操作相关联。
这适用于 .php 文件(只需将它们放入批处理文件中)
Assoc .php=phpfile
Ftype phpfile="C:\Program Files (x86)\Notepad++\notepad++.exe" %1
Run Code Online (Sandbox Code Playgroud)
您可以复制这些行以根据需要添加其他基于文本的文件。
这是一个在 Windows 10 上对我有用的脚本
$exts=@("txt","log","csproj","sql","xml","flobble")
echo "## setting up file associations"
foreach ($ext in $exts){
$extfile=$ext+"file"
$dotext="." + $ext
cmd /c assoc $dotext=$extfile
cmd /c "ftype $extfile=""C:\Program Files (x86)\Notepad++\notepad++.exe"" ""%1"""
echo ""
}
Run Code Online (Sandbox Code Playgroud)
https://gist.github.com/timabell/bc90e0808ec1cda173ca09225a16e194
感谢其他答案提供了我完成这项工作所需的信息。
归档时间: |
|
查看次数: |
52838 次 |
最近记录: |