File size: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(add task to aarch64 assembly raspberry pi)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(8 intermediate revisions by 6 users not shown)
Line 1,216:
<syntaxhighlight lang="frink">println[newJava["java.io.File", "input.txt"].length[]]
println[newJava["java.io.File", "/input.txt"].length[]]</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn DoIt
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
CFURLRef url = fn URLByAppendingPathComponent( desktopURL, @"test_file.txt" )
CFDictionaryRef attributes = fn FileManagerAttributesOfItemAtURL( url )
printf @"%@", fn DictionaryObjectForKey( attributes, NSFileSize )
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
 
=={{header|Gambas}}==
Line 1,285 ⟶ 1,299:
fsize 'input.txt';'/input.txt'</syntaxhighlight>
 
=={{header|JavaJakt}}==
<syntaxhighlight lang="javajakt">import java.io.File;
fn file_size(filename: String) throws -> i64 {
 
mut result = 0
public class FileSize
mut file = File::open_for_reading(filename)
{
mut buffer = [0u8; 1024] // Size of buffer is arbitrary
public static void main ( String[] args )
while true {
let read_bytes = file.read(buffer)
System.out.println("input.txt : " + new File("input.txt").length() + " bytes");
if read_bytes == 0 {
System.out.println("/input.txt : " + new File("/input.txt").length() + " bytes");
break
}
result += read_bytes as! i64
}
return result
}
 
 
fn main() {
println("{}", file_size(filename: "input.txt"))
println("{}", file_size(filename: "/input.txt"))
}
</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.io.File;
</syntaxhighlight>
<syntaxhighlight lang="java">
public static void main(String[] args) {
File fileA = new File("file.txt");
System.out.printf("%,d B%n", fileA.length());
File fileB = new File("/file.txt");
System.out.printf("%,d B%n", fileB.length());
}
</syntaxhighlight>
<pre>
108 B
108 B
</pre>
 
=={{header|JavaScript}}==
Line 1,355 ⟶ 1,396:
<syntaxhighlight lang="lang">
# Load the IO module
# Replace "<pathToIO.lm>" with the location where the io.lm langLang module was installed to without "<" and ">"
ln.loadModule(<pathToIO.lm>)
 
Line 1,950 ⟶ 1,991:
 
}</syntaxhighlight>
 
=={{header|S-BASIC}}==
The CP/M operating system -- S-BASIC's native environment --
reports file size as the number of 128-byte records. CP/M also
has no notion of a "root" directory, user area 0 on drive A (the
default on boot-up) being the closest analog. Although S-BASIC has a
built-in SIZE function, it returns the number of blocks
(allocation groups) occupied by the file -- which
varies with the disk format -- and even then
gives the wrong answer if a directory entry controls more than
one 16K logical extent.
<syntaxhighlight = "BASIC">
rem Set the logged drive ('A' to 'P')
procedure setdrive (drive = char)
var hl, de, bc, a_psw = integer
rem -- make sure drive letter is upper case!
if drive >= 'a' then drive = drive - 32
hl = 0
de = drive - 65
bc = 0EH
a_psw = 0
call (5H,hl,de,bc,a_psw)
end
 
rem Set the CP/M user area (0 to 15)
procedure setuser (user = integer)
var hl, bc, a_psw = integer
hl = 0
bc = 20H
a_psw = 0
call (5H,hl,user,bc,a_psw)
end
 
comment
Return size of named file as number of 128-byte records;
assumes file name is upper case. If the file does not
exist, the size will be reported as 0.
end
function fsize(filename = string:20) = integer
var hl, de, bc, a_psw, p = integer
based fname = string:20
based sz = integer
dim byte workfcb(36)
location array de = workfcb
base fname at de
base sz at de + 33
fname = fcb$(filename)
rem See if drive was specified and set FCB accordingly
p = instr(1,filename,":")
if p = 0 then
workfcb(0) = 0
else
workfcb(0) = asc(mid(filename,p-1,1)) - 64
bc = 23H rem BDOS filesize function
call (5,hl,de,bc,a_psw) rem result stored in sz
end = sz
 
rem Exercise the function
 
var filename = string:20
filename = "INPUT.TXT"
rem First check current drive and user
print filename;" occupies";fsize(filename)*128;" bytes"
rem Then check startup directory (A0:)
setdrive 'A'
setuser 0
print "A0:INPUT.TXT occupies";fsize(filename)*128;" bytes"
 
end
</syntaxhighlight>
{{out}}
Although both instances of INPUT.TXT consist of a single line
("The quick brown fox jumps over the lazy red dog") they will
each be reported as occupying a 128-byte record.
<pre>
INPUT.TXT occupies 128 bytes
A0:INPUT.TXT occupies 128 bytes
</pre>
 
 
=={{header|Scala}}==
Line 2,238 ⟶ 2,358:
Dim root As New IO.FileInfo("\input.txt")
Console.WriteLine(root.Length)</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="Go">
import os
 
fn main() {
paths := ["input.txt", "./input.txt", "non_existing_file.txt"]
for path in paths {
if os.is_file(path) == true {println("The size of '${path}' is ${os.file_size(path)} bytes")}
else {println("Not found: ${path}")}
}
}
</syntaxhighlight>
 
{{out}}
<pre>
The size of 'input.txt' is 22 bytes
The size of './input.txt' is 22 bytes
Not found: non_existing_file.txt
</pre>
 
=={{header|Wren}}==
Line 2,243 ⟶ 2,383:
 
To check the size of a file in the root, just change "input.txt" to "/input.txt" in the following script.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
var name = "input.txt"
9,476

edits