Icons per Filetype

129 views
Skip to first unread message

stef.bm

unread,
May 26, 2011, 9:34:16 AM5/26/11
to dirhtml discussion group
Hi,

dirhtml is a really nifty utility.

I was just wondering if there might be a way to have small icons per
filetype (like one would have using a file browser, etc.) next to each
listed files?

pdf icon for /pdf, text icon for .txt, etc.

dirhtml

unread,
May 28, 2011, 2:02:06 PM5/28/11
to dirhtml discussion group
Yes, it is possible. To do it, you need to use a /FILE_MATCHES_...
section (as described in the dirhtml "Help -> Links" page).

First, copy all needed icons to a web location, or to the location
where the html file will be generated.

Next, create a text file that lists the file types and associated html
code. For example (to be saved in the dirhtml folder as "file matches
code.txt"):
/*.xlsx|*.xls|*.xlm|*.xslt
<img src="excel-icon.png" />
/*.pdf
<img src="pdf-icon.png" />
/NO_MATCH-DIRHTML
<img src="generic-icon.png" />

Finally, add this to the dirhtml script:
/FILE_MATCHES_BEFORE_A
file matches code.txt

Note that using "/>" is XHTML format. For regular html, use > to
close <img ...> tags.

If the icon files are on a server, use a fully qualified URL, for
example:
/*.xlsx|*.xls
<img src="http://my-domain.com/icons/excel-icon.png" />

stef.bm

unread,
May 30, 2011, 9:22:08 AM5/30/11
to dirhtml discussion group
Sounds good.
Will follow instructions and post again here if anything else needed.
Thanks.

stef.bm

unread,
May 30, 2011, 1:49:58 PM5/30/11
to dirhtml discussion group
Hi,

Your instructions work like a charm. Thanks.

Is there a reason why the icons have to be in same directory as where
the html file is generated and not in a different directory, provided
you use the proper path to define the filetypes and corresponding
icons in "file matches code.txt"?
For example, this does not seem to work:

/*.pdf
<img src="E:\My Documents\MyFolder\Icons\adobe_pdf.png">

where generated html file is in E:\My Documents\OtherFolder\file.html

dirhtml

unread,
May 31, 2011, 10:18:03 AM5/31/11
to dirhtml discussion group
Nope, the icons can be anywhere, including on the web or a \\local
\server.

dirhtml

unread,
May 31, 2011, 10:22:43 AM5/31/11
to dirhtml discussion group
You can't have spaces in URL's. They need to be replaced with %20, so
the link below should be:
<img src="E:\My%20Documents\MyFolder\Icons\adobe_pdf.png">
Message has been deleted

stef.bm

unread,
Jun 1, 2011, 1:04:55 PM6/1/11
to dirhtml discussion group
Right. I had missed the space between "My" and "Documents"; my bad.
Thanks.

dirhtml

unread,
Jun 5, 2011, 3:53:30 PM6/5/11
to dirhtml discussion group
Upon further investigation, I discovered that <img src="D:\folder\some-
icon.png" />...

Works in: Chrome, IE
Does not work in: Firefox
Has issues in: Opera

Firefox does not seem to like the drive reference, and shows nothing.
Opera shows an "image" box. It probably relates to Firefox and Opera
being strict about what files the browser can access from a given html
file.

An easy way to make it work on all browsers is to use a web link.

For example, in a DropBox public folder:
<img src="http://dl.dropbox.com/u/XXXXXX/icons/some-icon.png" />
Reply all
Reply to author
Forward
0 new messages