Rebol Programming/to-relative-file

USAGE:

edit
TO-RELATIVE-FILE file /no-copy /as-rebol /as-local 

DESCRIPTION:

edit

Returns the relative portion of a file if in a subdirectory, or the original if not.

TO-RELATIVE-FILE is a function value.

ARGUMENTS

edit
  • file -- File to check (local if string!) (Type: file string)

REFINEMENTS

edit
  • /no-copy -- Don't copy, just reference
  • /as-rebol -- Convert to REBOL-style filename if not
  • /as-local -- Convert to local-style filename if not

SOURCE CODE

edit
to-relative-file: func [
    {Returns the relative portion of a file if in a subdirectory, or the original if not.} 
    file [file! string!] "File to check (local if string!)" 
    /no-copy "Don't copy, just reference" 
    /as-rebol "Convert to REBOL-style filename if not" 
    /as-local "Convert to local-style filename if not" 
    /local tmp
][
    either string? file [
        if tmp: find/match file to-local-file what-dir [file: next tmp] 
        if as-rebol [file: to-rebol-file file no-copy: true]
    ] [
        file: any [find/match file what-dir file] 
        if as-local [file: to-local-file file no-copy: true]
    ] 
    unless no-copy [file: copy file] 
    file
]