Jump to content

Check that file exists: Difference between revisions

Added Wren
(Added Wren)
Line 2,770:
Console.WriteLine(If(IO.Directory.Exists(IO.Path.DirectorySeparatorChar & "output.txt"), _
"file exists", "file doesn't exists"))</lang>
 
=={{header|Wren}}==
Empty files and directories have been created beforehand.
 
To check a file or directory exists in the root, just change "input.txt" to "/input.txt" and "docs" to "/docs" in the following script.
 
Since in Linux an ''empty'' directory has a size of 4K bytes, we check the number of files it contains to confirm that it's empty.
<lang ecmascript>import "io" for Directory, File
 
for (name in ["input.txt", "`Abdu'l-Bahá.txt"]) {
System.print("%(name) exists? %(File.exists(name)), size %(File.size(name)) bytes")
}
 
var dir = "docs"
var exists = Directory.exists(dir)
// if it exists get number of files it contains
var files = Directory.list(dir).count
System.print("docs directory exists? %(exists), number of contained files %(files)")</lang>
 
{{out}}
<pre>
input.txt exists? true, size 0 bytes
`Abdu'l-Bahá.txt exists? true, size 0 bytes
docs directory exists? true, number of contained files 0
</pre>
 
=={{header|Yabasic}}==
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.