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

recursive directory copying...

 [1/6] from: tofo:695online at: 12-May-2003 16:16


Hey guys, I was just wondering if anyone has written a recursive directory copying script. I found %dir-mapper.r, but that just recreates the structure without copying. I'd like to do: this/sub/sub/sub/* --> that/sub/sub/sub/* has anyone already done this? if not, have any pointers? thanks, -tom

 [2/6] from: greggirwin:mindspring at: 12-May-2003 16:34


Hi Tom, t6c> I was just wondering if anyone has written a recursive directory copying t6c> script. I found %dir-mapper.r, but that just recreates the structure without t6c> copying. I'd like to do: You could start off with something like this to get a list of files. It isn't efficient, but it's short and easy. all-files: func [ {Returns a block of fully qualified filenames for the directory.} spec [file!] "Starting Directory" block [block!] "Block to append to" /deep "Recurse sub-directories." /local f-spec ][ spec: dirize spec foreach file read spec [ f-spec: join spec file either all [deep dir? f-spec] [ wait 0 all-files/deep f-spec block ][ if not dir? file [append block f-spec] ] ] block ] Now, just iterate over that list, apply constraints to what you want to copy, change the path for your target file (change/part, split-path, etc.), and use write/binary+read/binary to copy it. -- Gregg

 [3/6] from: antonr:iinet:au at: 13-May-2003 14:13


I wrote a tree function which works well so far. You can insert user-code to be executed as each directory is visited. eg: tree/quiet/code %start-dir/ [ print rejoin dir-path ; current relative directory foreach file files [print dir/:file] ; all the files ] Since you can modify the user-code block, you could easily change its behaviour for your purpose. Here's the necessary init code for a full example: rebsite: select load-thru http://www.reboltech.com/index.r [folder "Anton"] clear find rebsite %index.r do load-thru rebsite/library/include.r include [rebsite/library/tree.r [tree] rebsite/library/dir-utils.r [push pop]] tree %./ ; <- now use it... The downside to my tree is that it is quite big compared to recursive functions because it is stack-based, it needs 'push and 'pop from dir-utils, and 'include needs to be defined first. You could rip out the three functions you need from tree.r and dir-utils.r though. The upside is it works and seems to me to be quite stable. It catches errors and prints them out, but that doesn't stop the function. Here's a direct link: http://www.lexicon.net/anton/rebol/library/tree.r Anton Rolls.

 [4/6] from: Al:Bri:xtra at: 13-May-2003 19:26


tom wrote:
> I was just wondering if anyone has written a recursive directory copying
script. These two functions do the job for me. 'Recursive-read generates a block of directories and file names, another function not shown here inserts 'compress-ed data, then 'Unpack decompresses data, writes file and makes a directory as required. Recursive-Read: function [ "Recursively read Directory." Directory [file! url!] "The Directory to read." ] [Files Subdirectory] [ if exists? Directory [ Files: read Directory if block? Files [ foreach File Files [ if #"/" = last File [ Subdirectory: File foreach File read Directory/:Subdirectory [ append Files Subdirectory/:File ] ] ] ] Files ] ] Unpack: func [Pack [block!]][ parse Pack [ some [ set File file! set Data binary! ( make paren! [ write/binary File decompress Data ] ) | set File file! ( make paren! [make-dir/deep File] ) ] end ] ] Andrew Martin ICQ: 26227169 http://Valley.150m.com/

 [5/6] from: antonr:iinet:au at: 14-May-2003 1:44


Hi Andrew, Your unpack function's parse rule is setting 'File and 'Data. Should not those be declared local to the function? Maybe you ripped this func from some context that we are missing... Anton.

 [6/6] from: Al::Bri::xtra::co::nz at: 14-May-2003 17:37


Anton wrote:
> Your unpack function's parse rule is setting 'File and 'Data. > Should not those be declared local to the function? > Maybe you ripped this func from some context that we are missing...
Indeed, the entire context is this: make object! [ Unpacker: [ Rebol [ Name: 'Unpacker Title: "Unpacker" Date: (now) Needs: [Core 1.2.8] ; Earlier versions of Rebol don't have a correct 'make-dir. Purpose: "Self-extracting file unpacker." ] Unpack: func [Pack [block!]][ parse Pack [ some [ set File file! set Data binary! ( make paren! [ write/binary File decompress Data ] ) | set File file! ( make paren! [make-dir/deep File] ) ] end ] ] Unpack ; 'Case goes here. ] Note the Rebol header inside! :) But you have reminded me that this is bad style! Bad, Andrew! I've been setting a bad example. So here's how it should really look like: Unpack: function [Pack [block!]] [File Data] [ ;... Andrew Martin ICQ: 26227169 http://Valley.150m.com/