REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
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.
To determine if a file name is that of a directory, use the dir? function:
print dir? %file.txt
false
print dir? %.
true
The dir? function works with some network protocols as well:
print dir? ftp://www.rebol.com/pub/
true
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? ftp://www.rebol.com/file.txt
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? ftp://www.rebol.com/file.txt
To obtain the last modification date of a file, use the modified? function:
print modified? %file.txt
30-Jun-2000/14:41:55-7:00
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? ftp://www.rebol.com/file.txt
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? ftp://www.rebol.com/file.txt
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |