REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Ports: Directory Ports

Pending Revision

This document was written for R2 and has yet to be revised for R3.

Directory ports allow you to open direct access to file directories. Within the system, this is how most other directory functions are created.

When you open a directory, you gain direct access to the directory as a block of filenames:

mydir: open %intro/
forall mydir [print first mydir]
close mydir

You can advance to a specific position within a directory series and remove a file with code such as:

dir: open %.
remove next dir
close dir

This deletes the second file in the current directory. Similarly,

remove at dir 5

would delete the fifth file in the directory, and:

clear dir

would delete all of the files in the directory.

To delete all files that contain with the word "junk", you can write:

dir: open %intro/
while [not tail? dir] [
    either find first dir "junk" [remove dir][
        dir: next dir
close dir

The changes made to a directory are made when the directory is closed or when it is updated. To force the action to occur immediately use a line such as:

update dir

The method of directory access can also be used for changing the names of files. After the open, the line:

change at dir 3 %newname.txt

will rename the third file in the directory. Similarly, the names of any of the files in the directory can be changed.

Here is an example that renames all of the files in a directory by adding the word REBOL to their names:

dir: open %intro/
forall dir [insert first dir "REBOL"]
close dir

  TOC < Back Next > - WIP Wiki Feedback Admin