一次永久更改多个文件扩展名的关联(打开的程序等)的最简单方法是什么?
我的意思是说?
假设你使用文本编辑器不酷至今已开放TXT,数据,蝙蝠和美国广播公司文件。现在你有文本编辑器ReallyCool并且您希望如果有一个应用程序,其左侧有程序名称,右侧有与其关联的文件扩展名列表(假设它可以打开)。
有这样的事吗?
通常程序会在安装过程中更改这一点(有些甚至会在安装之前询问),但对于便携式程序,通常必须手动执行此操作,而对于打开大量不同文件扩展名的编辑器来说,这很快就会变得令人厌烦。
欢迎所有想法!
答案1
大约一年前,我编写了一个小批处理脚本来处理此类文本文件关联问题。大多数情况下,它都能正常工作,但有时(例如,在应用 Windows 更新后)关联会恢复为默认设置,如果发生这种情况,我将再次运行该批处理。
我在批处理脚本中选择了我最喜欢的 3 个文本编辑器。
- 记事本2(或者Notepad2-mod) 用于轻量级文本文件。默认安装目录:
%SystemRoot%
- 记事本++对于.sql .sh。默认安装目录:
%ProgramFiles%\Notepad++
- 編輯适用于大多数编程语言文本文件。默认安装目录:
%ProgramFiles%\EditPlus 3
您需要将它们更改为您喜欢的文本编辑器,并且需要将相应的文件类型更改为您的文件类型。
@echo off
echo --------------------------------------------------------------------------
echo Windows text file association
echo --------------------------------------------------------------------------
REM ----------------------------------------------------------------------------
REM References
REM ----------------------------------------------------------------------------
REM Windows file associations
REM http://vim.wikia.com/wiki/Windows_file_associations
REM
REM Managing Files from the Command Line - Assoc and Ftype
REM http://commandwindows.com/assoc.htm
REM
REM Adding Associations
REM http://winbeginners.com/articles/associations3.htm
REM
REM CClean scan result show some error about registry HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
REM
REM http://superuser.com/questions/212848/how-change-file-association
REM
REM Windows registry information for advanced users
REM http://support.microsoft.com/kb/256986
REM ----------------------------------------------------------------------------
REM setlocal enabledelayedexpansion
set PROGRAM_DIR=%%ProgramFiles%%
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGRAM_DIR=%%ProgramFiles(x86)%%
REM notepad2
set NOTEPAD2=%%SystemRoot%%\notepad2.exe
REM Notepad++
set NPP=%PROGRAM_DIR%\Notepad++\notepad++.exe
if not exist "%ProgramFiles%\Notepad++\notepad++.exe" set NPP=%NOTEPAD2%
REM EditPlus
set EDITPLUS=%PROGRAM_DIR%\EditPlus 3\editplus.exe
if not exist "%ProgramFiles%\EditPlus 3\editplus.exe" set EDITPLUS=%NPP%
REM ----------------------------------------------------------------------------
REM Text file
REM ----------------------------------------------------------------------------
assoc .csv=txtfile
REM CueSheet
assoc .cue=txtfile
REM ----------------------------------------------------------------------------
REM C/C++
REM ----------------------------------------------------------------------------
assoc .h=SourceCode.C
assoc .c=SourceCode.C
assoc .hpp=SourceCode.C
assoc .cpp=SourceCode.C
assoc .cxx=SourceCode.C
assoc .rc=SourceCode.C
assoc .inc=SourceCode.C
REM AMXModX Script
assoc .sma=SourceCode.C
REM ----------------------------------------------------------------------------
REM Java
REM ----------------------------------------------------------------------------
assoc .java=SourceCode.Java
REM BeanShell
assoc .bsh=SourceCode.Java
REM ZK Script
assoc .zs=SourceCode.Java
REM ----------------------------------------------------------------------------
REM C#
REM ----------------------------------------------------------------------------
assoc .cs=SourceCode.CSharp
REM ----------------------------------------------------------------------------
REM SQL
REM ----------------------------------------------------------------------------
assoc .sql=sqlfile
REM ----------------------------------------------------------------------------
REM Web
REM ----------------------------------------------------------------------------
REM assoc .css=CSSfile
REM assoc .html=htmlfile
REM assoc .htm=htmlfile
assoc .shtml=htmlfile
REM assoc .js=jsfile
assoc .htc=htcfile
assoc .zul=SourceCode.ZK.UI
assoc .zhtml=SourceCode.ZK.UI
assoc .jsp=SourceCode.JSP
assoc .jspx=SourceCode.JSP
assoc .php=SourceCode.PHP
assoc .asp=SourceCode.ASP
assoc .aspx=SourceCode.ASP
REM ----------------------------------------------------------------------------
REM Shell
REM ----------------------------------------------------------------------------
assoc .awk=SourceCode.Shell
assoc .sed=SourceCode.Shell
assoc .sh=SourceCode.Shell
assoc .ps=SourceCode.PowerShell
REM assoc .bat=batfile
REM assoc .cmd=cmdfile
REM 对于批处理文件,不修改默认关联,而仅仅修改“编辑”动作的关联
REM ----------------------------------------------------------------------------
REM Configuration
REM ----------------------------------------------------------------------------
REM assoc .ini=inifile
REM assoc .inf=inffile
assoc .cfg=cfgfile
assoc .conf=Configuration.POSIX
assoc .properties=Configuration.Java
assoc .svg=svgfile
REM reg add
REM ----------------------------------------------------------------------------
REM Misc
REM ----------------------------------------------------------------------------
REM assoc .dsn=ODBC.FileDSN
REM assoc .eml=Microsoft Internet Mail Message
REM assoc .hta=htafile
REM assoc .jnlp=JNLPFile
REM assoc .log=txtfile
assoc .m3u=m3ufile
REM assoc .mht=mhtmlfile
REM assoc .mhtml=mhtmlfile
REM assoc .nfo=MSInfo.Document
REM assoc .reg=regfile
REM assoc .rtf=rtffile
REM assoc .scp=txtfile
REM SELinux Targeted policy .te
assoc .te=txtfile
REM assoc .txt=txtfile
REM assoc .wsc=scriptletfile
REM assoc .WSF=WSFFile
REM assoc .WSH=WSHFile
REM assoc .wtx=txtfile
REM assoc .xaml=Windows.XamlDocument
REM assoc .xhtml=xhtmlfile
REM assoc .xml=xmlfile
call :np2_open txtfile inifile jsfile cfgfile Configuration.POSIX Configuration.Java
call :np2_edit batfile cmdfile jsfile WSFFile WSHFile regfile m3ufile ODBC.FileDSN "Microsoft Internet Mail Message"
call :ep_open cssfile xmlfile xslfile xsltfile SourceCode.C SourceCode.Java SourceCode.CSharp SourceCode.JSP SourceCode.PHP SourceCode.ASP SourceCode.ZK.UI
call :ep_edit xmlfile svgfile htmlfile xhtmlfile shtmlfile htafile htcfile rtffile JNLPFile
call :npp_open SourceCode.Shell SourceCode.PowerShell sqlfile
pause
goto :EOF
:np2_open
if "%~1"=="" goto :EOF
REM echo %NOTEPAD2% [Open] %1
ftype %1="%NOTEPAD2%" "%%1"
shift
goto np2_open
:np2_edit
if "%~1"=="" goto :EOF
echo %NOTEPAD2% [Edit] %1
reg add "HKLM\Software\Classes\%~1\shell\edit\command" /ve /t REG_EXPAND_SZ /f /d "\"%NOTEPAD2%\" \"%%1\""
shift
goto np2_edit
:npp_open
if "%~1"=="" goto :EOF
REM echo %NPP% [Open] %1
ftype %1="%NPP%" "%%1"
shift
goto npp_open
:npp_edit
if "%1"=="" goto :EOF
echo %NPP% [Edit] %1
reg add "HKLM\Software\Classes\%~1\shell\edit\command" /ve /t REG_EXPAND_SZ /f /d "\"%NPP%\" \"%%1\""
shift
goto npp_edit
:ep_open
if "%~1"=="" goto :EOF
REM echo %EDITPLUS% [Open] %1
ftype %1="%EDITPLUS%" "%%1"
shift
goto ep_open
:ep_edit
if "%~1"=="" goto :EOF
echo %EDITPLUS% [Edit] %1
reg add "HKLM\Software\Classes\%~1\shell\edit\command" /ve /t REG_EXPAND_SZ /f /d "\"%EDITPLUS%\" \"%%1\""
shift
goto ep_edit
答案2
从“文件类型”列表更改或创建文件关联
如果打开用命令不可用,请尝试以下步骤:
单击开始,然后点击控制面板。
点击文件夹选项。
点击文件类型选项卡文件夹选项窗口,其中将列出完整的文件类型及其关联。
单击新的并在框中输入文件扩展名,然后单击先进的。
选择文件类型的关联。
单击好的然后点击关闭.
再次打开文件。