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

REBOL 3 Concepts: Files: File and Directory Information

Pending Revision

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

There are a number of functions that provide useful information about a file, such as whether it exists, its file size in bytes, when it was last modified, and whether it is a directory.


Directory Check

To determine if a file name is that of a directory, use the dir? function:

print dir? %file.txt
print dir? %.

The dir? function works with some network protocols as well:

print dir?

File Existence

To determine if a file exists, use the exists? function:

print exists? %file.txt

To determine if a file exists before you read it, use:

if exists? file [text: read file]

To avoid overwriting a file you can check it with, use:

if not exists? file [write file data]

The exists? function also works with some network protocols:

print exists?

File Size

To obtain the byte size of a file, use the size? function:

print size? %file.txt

The size? function also works with some network protocols:

print size?

File Modification Date

To obtain the last modification date of a file, use the modified? function:

print modified? %file.txt

Not all operating systems keep track of the creation date of a file, so to keep REBOL scripts operating system independent only the last modification date is accessible.

The modified? function also works with some network protocols:

print modified?

Directory Information

The info? function obtains all file directory information at the same time. The information is returned as an object:

probe info? %file.txt
make object! [
    size: 306
    date: 30-Jun-2000/14:41:55-7:00
    type: 'file

To print information about all files in the current directory, use:

foreach file read %. [
    info: info? file
    print [file info/size info/date info/type]
build-guide.r 22334 30-Jun-2000/14:24:43-7:00 file
code/ 11 11-Oct-1999/18:37:04-7:00 directory
data.r 41 30-Jun-2000/14:41:36-7:00 file
file.txt 306 30-Jun-2000/14:41:55-7:00 file

The info? function also works with some network protocols:

probe info?

  TOC < Back Next > - WIP Wiki Feedback Admin