Re: Detecting file type extension in a bash script on linux

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 01/16/04


Date: 16 Jan 2004 21:18:58 GMT

On Fri, 16 Jan 2004 at 10:17 GMT, B Thomas wrote:
> Hi,
> I am trying to write a script that generates a html index of a
> directories contents. For this the scripts needs to detect the type of
> file (file extension) and accordingly put appropriate html code for an
> icon of that file type besite the file name. How may I do this ?
> sincerely

{
    echo "<html>
 <head>
  <title>Index of $PWD</title>
 </head>
 <body><ul>"

    for file in *
    do
      case $file in
          *.exe) img=exe.png; type="MS executable" ;;
          *.gif) img=gif.png; type="GIF image" ;;
          *.tgz|*.tar.gz) img=tgz.png; type="gzipped tar archive" ;;
          *.ps) img=postscript.png; type="PostScript file" ;;
          *[-.]sh) img=shell.png; type="shell script";;
          ## etc....
          *) type=unknown; img=default.png ;;
      esac
      printf "<li><a href=\"%s\">" "$file"
      printf "<img src=\"%s\" alt=\"%s\">\n" "$img" "$type"
    done
    printf " </ul>\n </body>\n</html>"
} > index.html

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: Detecting file type extension in a bash script on linux
    ... >>I am trying to write a script that generates a html index of a ... For this the scripts needs to detect the type of ... >>icon of that file type besite the file name. ... it's better to write the script as: ...
    (comp.unix.shell)
  • Re: Detecting file type extension in a bash script on linux
    ... >>I am trying to write a script that generates a html index ... >>html code for an icon of that file type besite the file name. ... If you don't mind "next" then the more typical awk syntax would be to ...
    (comp.unix.shell)
  • Re: Detecting file type extension in a bash script on linux
    ... > I am trying to write a script that generates a html index ... > html code for an icon of that file type besite the file name. ... A simple awk script ... Sample execution: ...
    (comp.unix.shell)
  • Re: Decoding html pages
    ... the HTML code that the PHP engine produces *from* the raw html code and that ... That's the case with practically any PHP "page" (or any by a ... server-side script generated page for that matter). ... Of course the script does load, when you load the proper page (else it would ...
    (comp.lang.javascript)
  • Re: HTML Code Produced by FP
    ... The OP is not using a script - he is designing a page that will be ... In pages I write that will be parsed by a Perl script I do not allow ... FrontPage to write any code. ... FP puts breaks (inserts html code) in places in the actual ...
    (microsoft.public.frontpage.programming)