REBOL Document

Suffix? - Function Summary


Summary:

Return the suffix (ext) of a filename or url, else NONE.

Usage:

suffix? path

Arguments:

path - The path argument. (must be: any-string)

Description:

The SUFFIX? function can be used to obtain the file extention (e.g. .exe, .txt, .jpg, etc.) that is part of a filename.


    print suffix? %document.txt
    .txt


    print suffix? %program.exe
    .exe


    print suffix? %dir/path/doc.txt
    .txt


    print suffix? %file.type.r
    .r


    print suffix? %filename
    none


    print suffix? http://www.rebol.com/doc.txt
    .txt

The suffix function can be used with any string datatype, but always returns a FILE! datatype if the suffix was found. This was done to allow code such as:


    url: http://www.rebol.com/docs.html
    if find [%.txt %.html %.htm %.doc] suffix? url [
        print [url "is a document file."]
    ]
    http://www.rebol.com/docs.html is a document file.

Related:

find - Finds a value in a series and returns the series at the start of it.
split-path - Splits a file or URL path. Returns a block containing path and target.


<Back | Index | Next>

Copyright 2004 REBOL Technologies