template::util::read_file (public)

 template::util::read_file path

Defined in packages/acs-templating/tcl/util-procs.tcl

Reads a text file.

Parameters:
path (required)
The absolute path to the file
Returns:
A string with the contents of the file.

Testcases:
sync_file_get_document, read_write_file
Source code:
    if {![file exists $path]} {
        error "File $path does not exist"
    }

    #
    # Use ad_try to make sure that the file descriptor is finally
    # closed.
    #
    ad_try {
        set fd [open $path]
        template::util::set_file_encoding $fd
        set text [read $fd]
    } on error {errMsg opts} {
        dict incr opts -level
        ns_log error "template::util::read_file on fd $fd: $errMsg,\n$::errorInfo"
        return -options [dict replace $opts -inside $opts$errMsg
    } finally {
        close $fd
    }

    return $text
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: