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

Simple newbie questions

 [1/4] from: meta:dimensional at: 29-May-2001 20:24


Hey Gurus, I'm trying to piece together hints from the documentation on Core with the "more to come" online docs for View. (I wish there was a complete manual for View and Core together that made it all clear.) Anyway, as an exercise to help learn this stuff while creating something useful, I've started the following View script for renaming files. I have empty blocks for actions and am not sure what syntax will to accomplish what I want. I have fields but am not sure how to grab their values and do the actual renaming of file names. I can describe this in pseudo code but haven't internalized the REBOL way yet. There are comments in the script below where I have questions. Any suggestions will be most appreciated. Thanks, -Jamie REBOL [Title: "Rename Files"] mypath: %. allfiles: read mypath sort allfiles view layout [ backdrop effect [gradient 60.0.150 60.10.60] text-list data allfiles [] ;desired action is click to fill in the selected file into the find field below. across label 53 "Path" mypath: field ;desired capability is to change the path value in the mypath variable and cause the text-list to update with the contents of the new path. below across label "Find" 53 Findme: field below across label "Replace" Replaceme: field below Button "Rename" [] ;desired action is click to cause all instances of the string in the Find field to be replaced with the string in the Replace field, for for every file name in the mypath variable's path. ]

 [2/4] from: arolls:bigpond:au at: 30-May-2001 17:31


Hi Jamie, have a look at this: rebol [ Title: "Jamie's Rename" File: %jamie-rename.r Date: 1-Jun-2001 Version: 1.0.0 Needs: [view] Author: "Anton Rolls" Language: 'English Purpose: {} ToDo: { - } History: [ 1.0.0 [30-May-2001 {First version} "Anton"] ] Notes: {} ] path: %./ ; initial path is current directory files: sort read path view lay: layout [ backdrop effect [gradient 60.0.150 60.10.60] file-list: text-list data files [ ; this is the action when we click an item in the text-list print ["picked" file-list/picked] find-f/text: either empty? file-list/picked [ copy "" ; user maybe used ctrl-click to unpick everything ][ last file-list/picked ; get the last item clicked on ] show find-f ] ;desired function is to cause the text-list to update ;with the contents of the new path. across label 53 "Path" path-f: field 139 form path [ print "path change" either error? err: try [ ; try this files: sort read path: to-file path-f/text ][ ; we had an error path-f/text: copy "" file-list/data: copy [] ][ ; everything went ok path-f/data: path file-list/lines: sort read path ] show [path-f file-list] ] return label "Find" 53 find-f: field 139 return label "Replace" replace-f: field 139 return button 200 "Rename (simulated)" [ ; simulate the rename print rejoin ["rename %" find-f/text " %" replace-f/text] ;this is the real thing ;;rename to-file find-f/text to-file replace-f/text ] ]

 [3/4] from: carl:cybercraft at: 30-May-2001 22:24


Hi Jamie, I see Anton's given you a more elaborate example than mine, but here you go anyway... This doesn't change real filenames, but just the ones in your 'allfiles block. Use the REBOL word 'rename for that. More comments below the script... REBOL [Title: "Rename Files"] mypath: %. get-files: does [allfiles: read mypath sort allfiles] get-files view layout [ backdrop effect [gradient 60.0.150 60.10.60] a-list: text-list data allfiles [ findme/text: a-list/picked show findme ] across label 53 "Path" a-path: field [ mypath: to-file a-path/text get-files a-list/lines: allfiles show a-list ] below across label "Find" 53 Findme: field below across label "Replace" Replaceme: field below Button "Rename" [ replace allfiles findme/text to-file replaceme/text sort allfiles a-list/lines: allfiles show a-list ] ] Note I'd changed your naming of the path in the layout from 'mypath to a-path, as the one in the layout would conflict with your other 'mypath. Leaving it as it is would cause 'mypath to be pointing to the field and not your original path. To get at the data in layout objects such as fields and so on, you access them and change them like I have in the button above. ie... findme/text returns the text in the objext after the 'findme word, while... a-list/lines: allfiles changes the "lines" (a block) in a-list to your 'allfiles block. And... show a-list updates the list onscreen. layout objects have a lot of variables such as 'text and 'lines, and a quick way to see the entire list (after a script has run and the variables have been set) is to just enter the likes of... probe first a-list at the Console. (DO NOT JUST ENTER probe a-list THOUGH AS REBOL WILL DISSAPEAR ON A VERY LONG QUEST! THE first IS IMPORTANT TO PREVENT THIS!:) The above returns.... [self type offset size span pane text color image effect data edge font para feel saved-area rate show? options parent-face old-offset old-size line-list changes face-flags action state style alt-action facets related words colors texts file var keycode reset styles init multi blinker pane-size dirty? help user-data flags sz iter sub-area sld sn lc lines picked cnt act slf text-pane] As I said, lots, with many of them not being used, but they're a help in guessing (and eventually reminding you) how you get at the data in layout objects. a-list's color for instance can be found by entering...
>> a-list/color
== 240.240.240 Hope that's of some help. And yes, we'd all like the full View docs... On 30-May-01, Jamie wrote:
> Hey Gurus, > I'm trying to piece together hints from the documentation on Core
<<quoted lines omitted: 36>>
> path. > ]
-- Carl Read [carl--cybercraft--co--nz]

 [4/4] from: meta:dimensional at: 30-May-2001 8:12


Thanks Anton and Carl. Most appreciated! Best Regards, -Jamie Anton wrote:
> Hi Jamie, > > have a look at this: >
(munch) Carl Read wrote:
> Hi Jamie, > > I see Anton's given you a more elaborate example than mine, but here > you go anyway...
(munch)

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted