Script Library: 1219 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: henrik

Documentation for: scan-dir.r


REBOL

Introduction

Contents:

1. Introduction
2. Examples
2.1 File Matching
2.2 Callback

1. Introduction

SCAN-DIR scans the given directory recursively and returns all files in it to the console with the relative path on each file. You can match files and perform callbacks on each file.

This function can be very time consuming, if you use it on the root of your disk.

2. Examples

A plain recursive read of the given directory:

>> scan-dir %./
== [... recursive list of files ...]

This returns each file with the path relative to the given directory.

>> scan-dir/absolute %./ 
== [... recursive list of files with absolute path ...]

This returns each file with absolute path instead of relative to the given directory.

2.1 File Matching

Matching specific files in the list:

>> scan-dir/match %./ ".r"
== [... recursive list of files ...]

This will match all files that have ".r" in the name and exclude everything else.

You can match files listed in strings, blocks and straight as files. So if you have a list of .r and .txt files, you want to act on, you can do it like this:

>> scan-dir/match %./ [".r" ".txt"]
== [... recursive list of files ...]

You can also mix types:

>> scan-dir/match %./ [".r" %test.txt [".txt" ".bin"]]
== [... recursive list of files ...]

2.2 Callback

When using the callback function, you give the current file as argument to the function.

>> scan-dir/callback %./ func [f] [print size? f]

This prints the size of each single file.

You can also mix /callback and /match.

Enjoy!

MakeDoc2 by REBOL- 27-Nov-2007