Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: index.r file in View

From: vdemong:club-internet at: 12-Mar-2002 23:19

I write this script, when i learn REBOL, to update my local directory: REBOL [ Title: "local index" Author: "Vincent" Email: [vdemong--club-internet--fr] Version: 0.1 Date: 24-May-2001/15:30 Type: 'utility Info: "Scan local folders and subfolders, update/create all %index.r" Purpose: { scan local folders and sub folders search rebol files: .r html files: .html .htm pdf files: .pdf images files: .png .jpg .gif text files: .txt create index files (index.r) for each folder and its subfolders. create thumbnail images of all images, use them as icons. } ] make-line: function [ "Build a line for an index file." file [file!] "File to index" /html "File type is html" /text "file type is text" /image "file type is image" img-file "Complete path of image file" /pdf "file type is pdf" ] [line thumb-file thumb-lay] [ line: copy "file " append line reduce [ {"} copy/part file find file "." {" %} file " icon " ] if html [append line "html"] if text [append line "text"] if image [ ;Create thumbnail icon thumb-file: append copy tn-dir copy/part file find file "." append thumb-file %.png thumb-lay: layout [ size 75x50 backdrop img-file effect [aspect] at 0x0 vtext bold "IMAGE" ] save/png thumb-file to-image thumb-lay ;Make transparent where is black append line compose ["%" (thumb-file) " effect [key 0.0.0]" ] ] if pdf [append line "pdf"] line ] index-folder: function [ "Create index for a directory and sub-diretories." folder [file!] "Directory to index." ] [ line info-file inf file f hdr src img-blk html-blk tn-dir] [ ;Delete info file info-file: append copy folder %index.r error? try [delete info-file] ;create index.r and Write minimal header write/append info-file "REBOL [type: 'index]" write/append/direct info-file newline fold: read folder foreach f fold [ file: append copy folder f inf: info? file either inf/type = 'directory [ line: copy "folder" append line reduce [ { "} f {" %} f ] write/append info-file line write/append info-file newline ;Recursive index index-folder file ][ switch find f "." [ %.r [ ;Don't index index files... if f <> %index.r [ line: copy "file " hdr: src: none if script? file [ ;Read header fields of script (use Title and Info fields) either error? try [set [hdr src] load/header/next file ] [ append line reduce [ {" } copy/part f find f "." {" } f ] ][ either ((find first hdr 'Title) <> none) and (hdr/Title <> Untitled ) [ append line reduce [ {"} hdr/Title {" %} f ] ][ append line reduce [ {" } copy/part f find f "." {" %} f ] ] if find first hdr 'Info [ append line reduce [ { info "} hdr/Info {"} ] ] ] ] ] ] %.htm [ line: make-line/html f] %.html [ line: make-line/html f] %.pdf [ line: make-line/pdf f] %.png [ line: make-line/image f file] %.jpg [ line: make-line/image f file] %.gif [ line: make-line/image f file] %.txt [ line: make-line/text f] ] write/append info-file line write/append info-file newline ] ] ] msg: { This script scan the local directory. Erase all index.r files, and rebuild them. Are you sure that you want that? } if request/confirm msg [ ;Create a directory for thumbnail images of images files tn-dir: append copy system/options/home %thumbnail/ error? try [make-dir tn-dir] ;index local folder local-dir: append copy system/options/home %local/ index-folder local-dir ]