Recursive directory read/delete
[1/10] from: al::bri::xtra::co::nz at: 20-Apr-2001 23:55
Anyone got a recursive directory deleter written?
Andrew Martin
Blind Man w/Elephant...
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[2/10] from: brett:codeconscious at: 20-Apr-2001 22:22
Hi Andrew,
I have something that works for me locally. Mixed results with ftp though.
http://www.codeconscious.com/rebol/rebol-scripts.html#FilesandUrls
Brett.
[3/10] from: cyphre:volny:cz at: 20-Apr-2001 15:39
Hello Andrew,
Here is my old function. Maybe you'll find it somehow usefull...
copy-dir: func [
copies/moves the whole dir structure
src [file!] "source directory"
dst [file!] "destination directory"
/move "just moves the whole dir structure"
][
if not exists? dst [make-dir/deep dst]
foreach file read src [
src-path: rejoin [src file]
dst-path: rejoin [dst file]
either dir? src-path [
copy-dir src-path dst-path
if move [
delete src-path
]
][
write/binary dst-path read/binary src-path
if move [
delete src-path
]
]
]
if move [delete src]
return true
]
Regards,
Cyphre
[4/10] from: ryanc:iesco-dms at: 20-Apr-2001 11:41
Andrew Martin wrote:
> Anyone got a recursive directory deleter written?
>
Its part of my chainsaw collection. --Ryan
erase: function [
"Recursively erase a directory structure, including files."
target [file!] "Directory to delete."
] [
dir-list
] [
either dir? target [
dir-list: read target
foreach filename dir-list [
either dir? rejoin [target filename ] [
erase rejoin [target filename ]
] [
delete rejoin [target filename ]
]
]
delete target
] [
delete target
]
]
file-copy: function [
"Recursively copy files."
source [file!] "Source directory or file."
destination [file!] "Destination directory or file."
] [
dir-list
] [
either dir? source [
dir-list: read source
foreach filename dir-list [
either dir? rejoin [source filename ] [
if not exists? rejoin [destination filename ] [ make-dir rejoin
[destination filename ] ]
file-copy rejoin [source filename ] rejoin [destination filename
]
] [
file-copy rejoin [source filename ] destination
]
]
] [
either dir? destination [
if not exists? destination [ make-dir destination ]
write/binary rejoin [ destination any [ find/last/tail source "/"
] ]
read/binary source
] [
write/binary destination read/binary source
]
]
]
[5/10] from: al:bri:xtra at: 21-Apr-2001 10:28
Thank you, Ryan!
Thank you, Richard!
Thank you, Brett!
:-)
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[6/10] from: allenk:powerup:au at: 21-Apr-2001 9:34
Hi Andrew,
I did one quite a while ago for delete, it should be at rebol.org.
delete-dirs.r, I
think it was called, might need an update for 2.3.
Cheers,
Allen K
[7/10] from: al:bri:xtra at: 23-Apr-2001 20:33
Andrew Martin wrote:
> Anyone got a recursive directory deleter written?
Thanks everyone for their solutions. They were very helpful. Here's my
solution to the problem:
Delete!: make object! [
_Delete: get 'delete
set 'Delete func [
"Deletes the specified file(s)."
Target [file! url!] "The file to delete."
/Any "Allow wild cards."
][
if exists? Target [
either Any [
_Delete/any Target
][
if dir? Target [
foreach File read Target [
Delete Target/:File
]
]
_Delete Target
]
]
none
]
]
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[8/10] from: ryanc:iesco-dms at: 23-Apr-2001 11:57
You always have to add a new level of enginuity, dont you? It will make a
fine addition to my chainsaw collection. BTW, do you have any more
recursive functions you would like to share?
--Ryan
Andrew Martin wrote:
> Andrew Martin wrote:
> > Anyone got a recursive directory deleter written?
<<quoted lines omitted: 29>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Ryan Cole
Programmer Analyst
www.iesco-dms.com
707-468-5400
I am enough of an artist to draw freely upon my imagination.
Imagination is more important than knowledge. Knowledge is
limited. Imagination encircles the world.
-Einstein
[9/10] from: al::bri::xtra::co::nz at: 24-Apr-2001 16:42
Recursive functions
Ryan wrote:
> BTW, do you have any more recursive functions you would like to share?
Nearly. I'm trying to get a handle in my head on nested structures -- blocks
within blocks -- and unpacking them into a flat structure. That should be a
more generic solution to the directory deleting problem and similar.
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[10/10] from: brett:codeconscious at: 26-Apr-2001 11:25
Re: Recursive directory read/delete
Hi Andrew,
Looks good. One point.
My experience has been that when using the dir? function on an FTP target it
will access the target causing a network read each time you use it - which
is entirely reasonable because it represents the question "is this a
directory?".
In my code I posted earlier, I use something like this test instead:
dirized?: func [f][equal? f dirize f]
The reason I do so, is that having got the results of READ on a directory -
rebol has told me which are directories - they are the ones with the / at
the end. Well, it seems to work... :)
Thus saving heaps of network activity.
Brett Handley.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted