0

I've got thousands of files with extensions ".0", ".1", ".2", etc. that I want to associate with Notepad++ (v7.5.8). They currently don't have any file association in Windows (Windows 10). Since they don't have any existing association, the solutions shown here aren't working for me.

Also, I'm looking to associate them in Windows, not in the N++ settings, since I access these files from Windows Explorer.

Merlin820
  • 13
  • 3
  • How many different file extensions are we talking about? You could associate a single file, export the key, then use Excel to generate the X keys by Cating strings – Ramhound Nov 29 '18 at 16:04

1 Answers1

0

Much easier than manually associating all the .# files, IMO, would be to set up a catch-all edit mode, using regedit:

  • HKEY_CLASSES_ROOT\*\shell: Add Key = Notepad++, set (Default) = Edit with &Notepad++
  • HKEY_CLASSES_ROOT\*\shell\Notepad++: Add Key = command, set (Default) to "c:\program files (x86)\notepad++\notepad++.exe" "%1" -- use the correct path to notepad++.exe for your system, and make sure to have the double-quotes around both the path and the %1, to make sure spaces are handled correctly.

Log off and back on, or reboot. Now, on any file in explorer, you should be able to right-click, select Edit with Notepad++, and voila!


Per-Extension Association (All Users)

Alternately, open up a cmd.exe window (run-as-admin if necessary), and run

assoc .1=DotNumber
ftype DotNumber="c:\program files (x86)\notepad++\notepad++.exe" "%1"
for %n in (0 1 2 3 4 5 6 7 8 9) DO assoc .%n=DotNumber 

If you want more .# extensions, add them to the for loop. If you want to set them from a batch file (setdotn-assoc.bat or setdotn-assoc.cmd) rather than at the cmd.exe prompt, need two % rather than just one, everything else is the same:

assoc .1=DotNumber
ftype DotNumber="c:\program files (x86)\notepad++\notepad++.exe" "%1"
for %%n in (0 1 2 3 4 5 6 7 8 9) DO assoc .%%n=DotNumber

Per-Extension Association (Just for Current User)

If you're having problems with permissions on All Users, you can try this to do the per-extension association, but just for the current user.

In case you were able to create DotNumber type, ftype DotNumber= to remove the existing definition.

Run the following from the command line (shouldn't even need an Administrator command line this time)

REG ADD     HKCU\Software\Classes\DotNumber                      /ve /d "DotNumber File" /f
REG ADD     HKCU\Software\Classes\DotNumber\Shell                /ve /d "open" /f
REG ADD     HKCU\Software\Classes\DotNumber\Shell\open           /ve /d "open DotNumber file" /f
REG ADD     HKCU\Software\Classes\DotNumber\Shell\open\command   /ve /d "\"c:\program files (x86)\notepad++\notepad++.exe\" \"^%1\"" /f
FOR %n in (0 1 2 3 4 5 6 7 8 9) DO REG ADD HKCU\Software\Classes\.%n /ve /d "DotNumber" /f

And if you want to check if it was written

REG QUERY   HKCU\Software\Classes\DotNumber /S
FOR %n in (0 1 2 3 4 5 6 7 8 9) DO REG QUERY HKCU\Software\Classes\.%n /S
PeterCJ
  • 660
  • 1
  • 5
  • 12
  • Thank you! The command window method seems to work, except it's a work computer and for each extension it just returns an "Access is denied" error, even when I run it as an admin. Darn. – Merlin820 Jan 31 '19 at 19:23
  • Did it create the filetype or not? `ftype DotNumber` will say "File type 'DotNumber' not found or no open command associated with it" if it wasn't created, otherwise it will show the definition... – PeterCJ Jan 31 '19 at 19:35
  • Added a "current-user-only" version in newest edit. This one shouldn't matter whether or not you have Admin privileges. At least, it worked for me in a non-admin window. – PeterCJ Jan 31 '19 at 20:12
  • The Current User version worked! I don't know much about registry stuff, mind explaining a few things? What does the value of each subkey you create mean? Like, does having HKCU\Software\Classes\DotNumber\Shell have the value "open" mean something in particular? Is "open" a magic word? Is having "Shell" in the registry tree also special? – Merlin820 Feb 01 '19 at 20:47
  • The other question I have, is with this setup Windows Explorer shows the type of each of these files as "DotNumber File". Is there a way to make it say "0 File" "1 File" "2 File" etc.? Even if it requires a lot more lines of code with slight changes, that's fine, I can set it up as a batch file – Merlin820 Feb 01 '19 at 20:50
  • "shell" as the key is important: this is what tells windows where to look for actions for the filetype. "open" is semi-important: keys under "shell" can have any name, but windows defaults to choosing "open" if there are multiple keys under "shell" and no default is specified. To have a different name for each extension, you would have to have a separate file type key for each -- instead of DotNumber, you would need Dot1, Dot2, ... all with the same info except name; they would then all go inside a multiline-`DO` (see [ss64: `FOR`](https://ss64.com/nt/for.html) for more `FOR-DO` syntax) – PeterCJ Feb 01 '19 at 21:49
  • It's really hard to get the escaping syntax right inside the FOR loop, especially if you're switching between command-line and bat file. If you only want it for .0 - .9, I might suggest copy/paste/edit to get each, rather than trying to make it all work in the loop. The `(x86)` in the NPP path makes it even harder, since that tends to close the DO loop accidentally... – PeterCJ Feb 01 '19 at 22:16
  • 1
    This has all been really helpful, thank you! And actually my NPP is in the regular program folders file, not x86, so I probably don't have to worry about that DO loop issue. Thanks again! – Merlin820 Feb 04 '19 at 15:16