Anonymous user
Check that file exists: Difference between revisions
Add Vlang V
(Added solution for Action!) |
(Add Vlang V) |
||
Line 2,990:
Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "output.txt"), _
"file exists", "file doesn't exists"))</lang>
=={{header|Vlang}}==
<lang go>// Check file exists in V
// Tectonics: v run check-that-file-exists.v
module main
import os
// starts here
pub fn main() {
// file and directory checks
_ := os.execute("touch input.txt")
println("os.is_file('input.txt'): ${os.is_file('input.txt')}")
// make doc directory in current dir if it doesn't exist
_ := os.execute("mkdir -p doc")
println("os.is_dir('doc'): ${os.is_dir('doc')}")
// check in the root dir
println("os.is_file('/input.txt'): ${os.is_file('/input.txt')}")
println("os.is_dir('/doc'): ${os.is_dir('/doc')}")
// check for file, with empty file
_ := os.execute("truncate -s 0 empty.txt")
println("os.is_file('empty.txt'): ${os.is_file('empty.txt')}")
// check for file, with exotic name
wfn := "`Abdu'l-Bahá.txt"
efn := wfn.replace_each(["'", r"\'", "`", r"\`"])
_ := os.execute('touch $efn')
println('os.is_file("$wfn"): ${os.is_file(wfn)}')
}</lang>
{{out}}
<pre>prompt$ v run check-that-file-exists.v
os.is_file('input.txt'): true
os.is_dir('doc'): true
os.is_file('/input.txt'): false
os.is_dir('/doc'): false
os.is_file('empty.txt'): true
os.is_file("`Abdu'l-Bahá.txt"): true</pre>
=={{header|Wren}}==
|