Skip to content

Instantly share code, notes, and snippets.

@timabell
Last active December 6, 2022 15:22
Show Gist options
  • Save timabell/bc90e0808ec1cda173ca09225a16e194 to your computer and use it in GitHub Desktop.
Save timabell/bc90e0808ec1cda173ca09225a16e194 to your computer and use it in GitHub Desktop.
set windows file associations
# https://gist.github.com/timabell/bc90e0808ec1cda173ca09225a16e194
# MIT license
$exts=@(
"csv",
"csproj",
"json",
"log",
"md",
"patch",
"sql",
"txt",
"xml")
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 ""
}
# see also:
# * https://superuser.com/q/406985/8271
# * https://gist.github.com/timabell/608fb680bfc920f372ac
@benestr
Copy link

benestr commented Feb 4, 2020

The %1 should be in quotes (cmd /c "ftype $extfile=""C:\Program Files (x86)\Notepad++\notepad++.exe"" ""%1"""), otherwise it breaks when opening files in folders with spaces, see notepad-plus-plus/notepad-plus-plus#4981 (comment)

@timabell
Copy link
Author

timabell commented Feb 6, 2020

good spot @benestr, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment