Hi, I'm new and I much prefer forums to mailing lists and the archaic BBS-like R3 chat. I've been busy chasing up and down the secret garden that is the Rebol web ecosystem and yesterday I finally tried to use Rebol to actually accomplish a small scripting task. Namely, I have a bunch of strangely named files that I need to organize better. I have "gal-1109/string_####/string_####.jpg" and I need to organize them into "gallery/string/string_####.jpg" for better overview. Unfortunately, I can't get the call command to work. What am I doing wrong? Improvements to code formatting, etc. are also welcome. Code: REBOL[] folders: read %/D/inspiration/gal-1109/ foreach folder folders [ tail: last parse folder "_" folder_new: parse folder "_" alter folder_new tail images: read join %/D/inspiration/gal-1109/ folder foreach image images [ source: join %/D/inspiration/gal-1109/ [folder image] dest: join %/D/inspiration/gallery/ [folder_new "/" image] probe rejoin ["copy " source " " dest] ] ]
I wasn't aware that 'call was working properly in R3. Here's a few ideas to get you going. try this instead: Code: foreach folder read folders: %/D/inspiration/gal-1109/ so you can now use 'folders everywhere you have %/D/inspiration/gal-1109/ Don't redefine Rebol core functions such as 'tail. Use a different word instead. Check to see that the file is a folder Code: if parse folder [ copy folder_new to "_" skip copy folder_tail to end ][ if not exists? folder_new: dirize to-file append folder_new folder_tail [ make-dir folder_new ] ... folder actions ... ] And you don't need 'call, you can use this in a loop Code: write dest read source
Thank you for your reply, but I failed to mention why I was using the tail variable. It's because some folders are named "string_stringg_####" and thus I only need to remove the number part at the end. I don't understand parse enough yet, but is it possible to start parsing from the end? Or would the correct way involve specifying that I need to chop the "_####" part?
Just said it was bad form to redefine existing functions Code: >> help tail USAGE: TAIL series DESCRIPTION: Returns the series at the position after the last value. TAIL is an action value. ARGUMENTS: series -- (Type: series port) Does this help Code: >> filename: %abcd_efgh_1234.jpg == %abcd_efgh_1234.jpg >> new_file: copy/part filename find filename find/last filename "_" == %abcd_efgh
Much better, thank you! But now a different kind of setback. In R3, are there some new security settings in place regarding file permissions? Because I'm getting Code: Access error: security violation: %/D/...jpg Where: read foreach foreach catch either either do begin do Near: read source
I'm not aware of any .. but you can presumably set permissions with secure none I would print out the source value to make sure it is a valid one.