Jump to content

Rebol Programming/to-relative-file

From Wikibooks, open books for an open world

USAGE:

[edit | edit source]
TO-RELATIVE-FILE file /no-copy /as-rebol /as-local 

DESCRIPTION:

[edit | edit source]

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 | edit source]
  • file -- File to check (local if string!) (Type: file string)

REFINEMENTS

[edit | edit source]
  • /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 | edit source]
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
]