/ Published in: Bash
URL: http://reboltutorial.com/blog/how-to-apply-a-function-to-all-files-in-a-directory-recursively/
I found foreach-file a fantastic script from Rebolek on Rebol.org that I slightly modified to make it more tolerant to directory path parameter which would not end with “/” character.
To use it, copy and paste the code above in Rebol’s console and then copy and paste the code below to print all the files names in Current and then in Windows directory:
print-file-name: func[file][ print file ] foreach-file %. :print-file-name foreach-file %/C/Windows :print-file-name
Expand |
Embed | Plain Text
foreach-file: func [ "Perform function on each file in selected directory recursively" dir [file! url!] "Directory to look in" act [function!] "Function to perform (filename is unput to fuction)" /directory "Perform function also on directories" /local f files ][ if not equal? last dir #"/" [ dir: to-rebol-file join dir #"/" ] files: attempt [read dir] either none? files [return][ foreach file files [ f: join dir file either dir? f [ either directory [ act f foreach-file/directory f :act ][ foreach-file f :act ] ][act f] ] ] ]
You need to login to post a comment.
