|REBOL 3 Docs||Guide||Concepts||Functions||Datatypes||Errors|
|TOC < Back Next >||Updated: 6-Feb-2009 Edit History|
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] CVS/ history.t intro.t overview.t quick.t
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:
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:
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 >||REBOL.com - WIP Wiki||Feedback Admin|