Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get information about a file extension association

20 views
Skip to first unread message

Timo Salmi

unread,
Mar 4, 2006, 2:43:37 PM3/4/06
to
DRAFT

@echo off & setlocal enableextensions
::
if "%~1"=="" (
echo Usage: %~0 Extension
goto :EOF
)
set ext_=%~1
::
for /f "tokens=2 delims==" %%a in (
'assoc^|find /i "%ext_%"') do set assoc_=%%a
echo %ext_% %assoc_%
if defined assoc_ (
reg query HKLM\SOFTWARE\Classes\%assoc_%|find "REG_SZ"
) else (
echo No association)
endlocal & goto :EOF

The output might be e.g.

C:\_D\TEST>cmdfaq .html
.html FirefoxHTML
AlwaysShowExt REG_SZ
<NO NAME> REG_SZ HTML Document

C:\_D\TEST>cmdfaq .dir
.dir
No association

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

Timo Salmi

unread,
Mar 4, 2006, 3:01:02 PM3/4/06
to
Timo Salmi wrote:
> if defined assoc_ (
> reg query HKLM\SOFTWARE\Classes\%assoc_%|find "REG_SZ"
reg query HKLM\SOFTWARE\Classes\%assoc_%\shell|find "shell\"

> ) else (
> echo No association)
> endlocal & goto :EOF

The addition gives the programs associated with the extension.

Clay Calvert

unread,
Mar 4, 2006, 11:30:08 PM3/4/06
to
On Sat, 04 Mar 2006 21:43:37 +0200, Timo Salmi <t...@uwasa.fi> wrote:

Have you looked at the Ftype command? I've got a script at work that
has more substance than the one-liner below, but it covers the
concept.

for /f "tokens=1* delims==" %%a in ('assoc %1') do ftype %%b

Thanks,
Clay Calvert
CCal...@Zanguru.com
Replace "Z" with "L"

Message has been deleted
Message has been deleted
Message has been deleted

Timo Salmi

unread,
Mar 5, 2006, 2:54:09 AM3/5/06
to
Clay Calvert wrote:
> On Sat, 04 Mar 2006 21:43:37 +0200, Timo Salmi <t...@uwasa.fi> wrote:
> for /f "tokens=1* delims==" %%a in ('assoc %1') do ftype %%b

That is very nice. Thank you Clay.

Let's test a bit with yours included

@echo off & setlocal enableextensions
::
if "%~1"=="" (
echo Usage: %~0 Extension
goto :EOF
)
set ext_=%~1
::
for /f "tokens=2 delims==" %%a in (
'assoc^|find /i "%ext_%"') do set assoc_=%%a

echo Timo:
echo %ext_% %assoc_%
::
echo Clay:


for /f "tokens=1* delims==" %%a in ('assoc %1') do ftype %%b

::
endlocal & goto :EOF

Example 1 (ok)

C:\_D\BAS>cmdfaq .html
Timo:
.html FirefoxHTML
Clay:
FirefoxHTML=C:\PROGRA~1\MOZILL~1\FIREFOX.EXE -url "%1"

Example 2 (bafflement)
C:\_D\BAS>cmdfaq .lst
Timo:
.lst ft000016 [which can be used to get further information on .lst]
Clay:
File type 'ft000016' not found or no open command associated with it.

But I have .lst associated. From folder options, edit file type:
LST list text file
The SemWare Editor Professional
"C:\Program Files\TSEPro\tse32.exe" "%1"

Some limitations would appear to be in place with FTYPE.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Message has been deleted

Timo Salmi

unread,
Mar 5, 2006, 3:46:01 AM3/5/06
to
Clay Calvert wrote:
> On Sat, 04 Mar 2006 21:43:37 +0200, Timo Salmi <t...@uwasa.fi> wrote:
> for /f "tokens=1* delims==" %%a in ('assoc %1') do ftype %%b

(My apologies for the potential repeat. The server is acting up.)

That is very nice. Thank you Clay.

Let's test a bit with yours included

@echo off & setlocal enableextensions


::
if "%~1"=="" (
echo Usage: %~0 Extension
goto :EOF
)
set ext_=%~1
::
for /f "tokens=2 delims==" %%a in (
'assoc^|find /i "%ext_%"') do set assoc_=%%a

echo Timo:
echo %ext_% %assoc_%
::
echo Clay:

for /f "tokens=1* delims==" %%a in ('assoc %1') do ftype %%b

::
endlocal & goto :EOF

Example 1 (ok)

C:\_D\BAS>cmdfaq .html
Timo:
.html FirefoxHTML
Clay:
FirefoxHTML=C:\PROGRA~1\MOZILL~1\FIREFOX.EXE -url "%1"

Example 2 (bafflement)
C:\_D\BAS>cmdfaq .lst
Timo:
.lst ft000016 [which can be used to get further information on .lst]
Clay:
File type 'ft000016' not found or no open command associated with it.

But I have .lst associated. From folder options, edit file type:
LST list text file
The SemWare Editor Professional
"C:\Program Files\TSEPro\tse32.exe" "%1"

Some limitations would appear to be in place with FTYPE.

All the best, Timo

Timo Salmi

unread,
Mar 5, 2006, 4:34:28 AM3/5/06
to
Timo Salmi <t...@uwasa.fi> wrote:
> Clay Calvert wrote:
> > On Sat, 04 Mar 2006 21:43:37 +0200, Timo Salmi <t...@uwasa.fi> wrote:

> > for /f "tokens=1* delims==" %%a in ('assoc %1') do ftype %%b

> Let's test a bit with yours included
(SNIP)


> Example 2 (bafflement)
> C:\_D\BAS>cmdfaq .lst
> Timo:
> .lst ft000016 [which can be used to get further information on .lst]
> Clay:
> File type 'ft000016' not found or no open command associated with it.
>
> But I have .lst associated. From folder options, edit file type:
> LST list text file
> The SemWare Editor Professional
> "C:\Program Files\TSEPro\tse32.exe" "%1"
>
> Some limitations would appear to be in place with FTYPE.

Got it now. The "Action" in File Types must exclicitly be "open".

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland

RazTK

unread,
Mar 5, 2006, 6:53:15 AM3/5/06
to
@echo off
for %%? in (%*) do call :Check %%?
goto :eof
:Check
echo.
for /f "delims=." %%a in ("%~1") do (for /f "tokens=2 delims==" %%b in
('assoc .%%a 2^>nul') do (for /f "tokens=2 delims==" %%c in ('ftype %%b
2^>nul') do (echo %%a : %%b) & (echo %%b : %%c)) || (echo %%a : %%b))
|| (echo '%~1' not found.)
goto :eof

ten.n...@virgin.net

unread,
Mar 5, 2006, 3:03:38 PM3/5/06
to

RazTK, I prefer the code formatted for easier understanding!

I have added the missing carets to your STDERR redirects
::-----START-----
01;@ECHO OFF&SETLOCAL ENABLEEXTENSIONS
02;FOR %%? IN (%*) DO CALL :CHECK %%?
03;ENDLOCAL&GOTO :EOF
04;:CHECK
05;ECHO/
06;FOR /F "DELIMS=." %%A IN ("%~1") DO (
07; FOR /F "TOKENS=2 DELIMS==" %%B IN ('ASSOC .%%A ^2^>NUL') DO (
08; FOR /F "TOKENS=2 DELIMS==" %%C IN ('FTYPE %%B ^2^>NUL') DO (ECHO/%%A : %%B)&(ECHO/%%B : %%C)
09; )||(ECHO/%%A : %%B)
10; )||(ECHO/'FILE EXTENSION %~1' NOT FOUND.)
11;GOTO :EOF
::------END------
And prettied a little

Note: Line numbers, 'nn;', included to prevent line wrap, should be removed

RazTK

unread,
Mar 6, 2006, 12:23:20 AM3/6/06
to
Thank you for making my code more easy to understand.
However, there is no need for my "missing carets", at least on my
system.
0 new messages