REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: write

write  destination  data  /part  length  /seek  index  /append  /allow  access  /lines

Writes to a file, URL, or other port - auto-converts text strings.


destination [port! file! url! block!]

data [binary! string! block!] - Data to write (non-binary converts to UTF-8)


/part - Partial write a given number of units

length [number!]

/seek - Write at a specific position

index [number!]

/append - Write data at end of file

/allow - Specifies protection attributes

access [block!]

/lines - Write each value in a block as a separate line

See also:

read   open   close   load   save   form  


WRITE is typically used to write a file to disk, but many other operations, such as writing data to URLs and ports, are possible.

Normally a string or binary value is provided to this function, but other types of data such as a number or a time can be written. They will be converted to text.

The /BINARY refinement will write out data as its exact representation. This is good for writing image, sound and other binary data.

The /STRING refinement translates line terminators to the operating system's line terminator. This behavior is default.

The /APPEND refinement is useful logging purposes, as it won't overwrite existing data.

The /LINES refinement can take a block of values and will write each value to a line. By default, WRITE will write the block of values as a concatonated string of formed values.

The /PART refinement will read the specified number of elements from the data being written. The /WITH refinement converts characters, or strings, specified into line terminators.

See the User's Guide for more detailed explanation of using READ and its refinements.

write %junkme.txt "This is a junk file."
write %datetime.txt now
write/binary %data compress "this is compressed data"

write %rebol-test-file.r "some text"
print read %rebol-test-file.r
write/append %rebol-test-file.r "some more text"
print read %rebol-test-file.r

write %rebol-test-file.r reduce ["the time is:" form now/time]
print read %rebol-test-file.r
write/lines %rebol-test-file.r reduce ["time is:" form now/time]
print read %rebol-test-file.r

write/part %rebol-test-file.r "this is the day!" 7
print read %rebol-test-file.r

  TOC < Back Next > - WIP Wiki Feedback Admin