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

REBOL 3 Functions: request-file

request-file  /save  /multi  /file  name  /title  text  /filter  list

Asks user to select a file and returns full file path (or block of paths).

Refinements:

/save - File save mode

/multi - Allows multiple file selection, returned as a block

/file

name [file!] - Default file name or directory

/title

text [string!] - Window title

/filter

list [block!] - Block of filters (filter-name filter)

See also:

to-local-file   to-rebol-file  

Contents

Description

Opens the standard operating system file requester to allow the user to select one or more files.

Details

Normal usage for read or load

The line:

file: request-file

will open the file requester and return a single file name as a full file path. This is normally used to read or load files.

If the user clicks CANCEL or closes the file requestor, a NONE is returned.

For saving or writing files

To open the file requester to save a file:

file: request-file/save

This will change the text of the window to indicate that a save (write) will be done.

Specifying a default file or directory

A default name can be provided for the file:

file: request-file/file %test.txt

This also works with the /save option, and a full path can be provided, in which case the requester will show the directory where the file will be found.

In addition, just a directory can be used:

file: request-file/file %/c/data/files/

Be sure to include the terminating slash to indicate a directory. Otherwise it will be treated as a file.

Allowing multiple file selection

To allow the selection of multiple files at the same time:

files: request-file/multi

foreach file files [print file]

The result is returned as a block, and each file within the block is a full path.

Filtering file views

You can also provide file list filters to show only specific files. For example:

file: request-file/filter [
    "REBOL Scripts" "*.r"
    "Text files" "*.txt"
]

Setting the window title

The /title refinement lets you modify the window title for the file requester to help make it more clear to users.

file: request-file/save/title "Save your data file"
either file [save file data] [print "data not saved"]
Changes from R2

This function contains minor changes and cleanup relative to R2. Note that the default operation (with no refinements) returns a single file, not a block. This is the most common form of operation, so it is made standard here. In addition, the /multi option returns a block of full file paths, not a directory path followed by relative files.


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin