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

[REBOL] Re: check me? deleting files based on a pattern

From: antonr:iinet:au at: 3-Nov-2003 13:48

RebOldes' code below is not as fast as possible yet, I think, though less likely to write a bug by missing or adding an extra [ next dir-port ], and it is less code to maintain, still... If you look at source delete, it is opening a directory port to do its work. Better to use remove on a direct port, rather than delete, no? I refer you to Chapter 14 - Ports, section 8.3 Direct Port Access See an example using remove at bottom.....
> If there is too many files you may try to open the directory as a > port without buffering: > > files: open/direct base > while [not tail? files][ > file: first files > if find file "editpost" [ > if error? set/any 'err try [delete base/:file][ > print mold disarm err > ] > ] > files: next files > ] > close files > > -- > Best regards, > rebOldes -----------------[ ]
; create some files to play with repeat n 10 [save join %editpos [#"p" + to-integer (n / 2) n // 2] none] ; list the files foreach file read %. [print file] prin "Press enter key..." input "" ; selectively delete some of the files base: %. ; current directory dir-port: open/direct base while [not tail? dir-port][ file: first dir-port ?? file either find file "editpost" [ either error? set/any 'err try [remove dir-port][ print mold disarm err ; remove not successful, therefore must move to the next file dir-port: next dir-port ][ ; successfully removed a file from dir-port print "------- removed" ] ][ ; didn't match selection, move to the next file dir-port: next dir-port ] ] close dir-port Anton.