Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Select dir modification
Pages: [1] Print
Author Topic: Select dir modification  (Read 599 times)
JohnW
Newbie
*
Offline Offline

Posts: 9


View Profile
Select dir modification
« on: October 03, 2006, 03:55:36 PM »

I would like to know if there is a way to modify this script to select the directory instead of having it hard coded in...

Code:
REBOL [Title: "HTML Thumbnail Photo Generator"]

    dir: %product/

    make-dir/deep dir/small ; where to keep the thumb

    html: "<HTML>"
    emit: func [data]
    [repend html data] ; (cookbook example 0006)

    view/new layout [
        backdrop 00.00.00
        i1: image 100x100 effect [aspect]
        t1: text 80 bold
        button 80 "Quit" [quit]
    ]

    emit [
     <LINK REL="StyleSheet" HREF="style.css" TYPE="text/css" MEDIA="screen">newline
     <BODY scroll="auto">newline
<TABLE class="album" CELLSPACING="6" CELLPADDING="4">newline
    ]

    n: 0
    foreach file load dir [
        ; Process image files only:
        if find [%.jpg %.gif] suffix? file [
            ; Load the image and show its icon:
            file: lowercase file
            photo: load dir/:file
            i1/image: photo
            t1/text: file
            show [i1 t1]
            wait 0 ; check Quit button

            ; Create a name for the icon file:
            icon: copy file
            clear find/reverse tail icon "."
            append icon ".png"

            ; Save the icon image:
            save/png dir/small/:icon to-image i1

            ; Add table cell links (and row break if needed):
            if zero? n // 6 [emit <TR>]
            emit [
                newline <TD align="center" valign="middle">
                {<A HREF="} file {" target="_blank">}
                {<IMG SRC="small/} icon {" border="0">}
                </A>
                </TD>
            ]
            n: n + 1
            new-row: zero? n // 6
            if new-row [emit </TR>]
        ]
    ]
    if not new-row [emit </TR>]
    emit [newline
</TABLE>
newline
    ]
    write dir/album.html html

    browse dir/album.html

I have tried several variations but I cannot figure it out, John.

Logged
PeterWood
Newbie
*
Offline Offline

Posts: 28


View Profile
Re: Select dir modification
« Reply #1 on: October 03, 2006, 07:35:21 PM »

Try replacing:

Code:
dir: %product/

with

Code:
dir: request-dir
Logged
JohnW
Newbie
*
Offline Offline

Posts: 9


View Profile
Re: Select dir modification
« Reply #2 on: October 03, 2006, 09:56:01 PM »

Tried that, unfortunately it produces the following...

Code:
** Script Error: new-row has no value
** Near: if not new-row [emit </TR>]
emit
>>
Logged
Anton
Jr. Member
**
Offline Offline

Posts: 65

Rebol veteran


View Profile WWW
Re: Select dir modification
« Reply #3 on: October 03, 2006, 11:52:04 PM »

Hi, I think you got that error because the directory you selected contained no .jpg or .gif files, therefore NEW-ROW was never set a value at all (it is a completely unset word).
So trying (after the loop) to get the value of new-row makes an error.

If you open a new console and type:

  >> new-row
  ** Script Error: new-row has no value
  ** Near: new-row

you can see the same error.

A solution is to give a new-row an initial value (eg. NONE or FALSE) so that it always has a value. eg:

    n: 0
    new-row: none
    foreach file ...

or alternatively you could only try to use new-row's value when you know it has one:

    if all [n > 0 not new-row][emit </TR>]

(That requires you to think more carefully to understand the code, however.)

On an extra note, the line

Logged
Anton
Jr. Member
**
Offline Offline

Posts: 65

Rebol veteran


View Profile WWW
Re: Select dir modification
« Reply #4 on: October 03, 2006, 11:56:21 PM »

On an extra note, the line

    file: lowercase file
   
will break the filenames on some filesystems. To be os-independant it's better to preserve the case of filenames.
Logged
JohnW
Newbie
*
Offline Offline

Posts: 9


View Profile
Re: Select dir modification
« Reply #5 on: October 04, 2006, 06:48:28 AM »

 I did forget to put the images in the folder, thank you Peter, and Anton it works!

Logged
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Select dir modification
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 07, 2008, 11:31:11 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2241 Posts in 585 Topics by 2232 Members
Latest Member: ThortHoTeMorY

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc