Associate file by name rather than extension?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Oct 18, 2009
109
4
#1
Is it possible in Windows 7 to associate a file with a program based on the file name not the extension?

We download a variety of files that have standard names but all have a .TXT extension. I need to open them in Excel and that means right-click, select Open With ..., select Excel 2016. Obviously I don't want to open EVERY .txt file in Excel. The association would need to be for something like DAILY_PMT_ccyymmdd.TXT
 

samintz

Scott Mintz
May 20, 2008
1,232
11
Solon, OH, USA
#2
Short answer: no

Long answer: Create a script that does the magic parsing. Associate .TXT files with a new ftype and invoke that ftype by running TCC and your script and pass in the file name. Then have the script invoke either the current TXT file handler or Excel.

This is untested:
Code:
ftype dailypmt="C:\TC22\TCC.EXE" /c C:\TC22\dailypmt.btm "%1"
assoc .txt=dailypmt

dailypmt.btm:
iff %# == 0 then
  echo usage: dailypmt txtfile
  quit
endiff
iff %@regex["DAILY_PMT_.+\.TXT",%1] == 1 then
  start /pgm excel %1
else
  set txtfile=%@execstr[ftype txtfile]
  start /pgm %txtfile
endiff