Qu

touch

Builtin index · File I/O

touch(path)

Input: path · Output: no output

What it is

Unix touch semantics. path (string) is the filesystem path: creates an empty file if it doesn't exist; if it already exists, updates its modification time WITHOUT altering its content.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
touch(path)
path stringnot documented yet
no outputUnix touch semantics.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

fires = 0
watch file("config.txt") do
    fires = fires + 1
end
f1 = pump_watches()      # nothing changed yet -> 0

touch("config.txt")      # real mtime bump (creates the file if missing)

f2 = pump_watches()      # -> 1

f3 = pump_watches()      # nothing changed since f2's check -> 0

from tour

fires = 0
watch file("config.txt") do
    fires = fires + 1
end
pump_watches()          # nothing changed yet -> 0 fired

print(fires)             # 0

touch("config.txt")
pump_watches()          # real mtime change -> 1 fired

print(fires)             # 1

output
· pump_watches(): 0 watch firing(s) across 1 registered watch(es)
0
· pump_watches(): 1 watch firing(s) across 1 registered watch(es)
1

from concurrency

function load_and_process(path)
    profiling_mode(true)
    data = read_csv(path, headers=true)
    result = data.sort_by("value")
    profiling_mode(false)
    print(profile_stats())     # a real Table: function / calls / seconds


    sandbox_mode(true)
    try
        touch("audit.log")     # denied -- sandboxed for this section only

    catch err
        print("blocked: {err.message}")
    end
    sandbox_mode(false)

    return result
end function

from quickstart

path = "touch_target.txt"
had_before = file_exists(path)
touch(path)
exists_after_touch = file_exists(path)

f = fopen(path, "w")
write_line(f, "original content")
close(f)

touch(path)                 # existing file: content must survive untouched


g = fopen(path, "r")
content = read_all(g)
close(g)

print("had_before = {had_before}")
print("exists_after_touch = {exists_after_touch}")
print("content = {content}")

from tour