This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
In this task, the job is to verify the size of a file called "input.txt" for a file in the current working directory and another one in the file system root.

View file

@ -0,0 +1,2 @@
---
note: File System Operations

View file

@ -0,0 +1 @@
PROC set = (REF FILE file, INT page, line, character)VOID: ~

View file

@ -0,0 +1,8 @@
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_File_Size is
begin
Put_Line (File_Size'Image (Size ("input.txt")) & " bytes");
Put_Line (File_Size'Image (Size ("/input.txt")) & " bytes");
end Test_File_Size;

View file

@ -0,0 +1,4 @@
FileGetSize, FileSize, input.txt ; Retrieve the size in bytes.
MsgBox, Size of input.txt is %FileSize% bytes
FileGetSize, FileSize, \input.txt, K ; Retrieve the size in Kbytes.
MsgBox, Size of \input.txt is %FileSize% Kbytes

View file

@ -0,0 +1,11 @@
file% = OPENIN(@dir$+"input.txt")
IF file% THEN
PRINT "File size = " ; EXT#file%
CLOSE #file%
ENDIF
file% = OPENIN("\input.txt")
IF file% THEN
PRINT "File size = " ; EXT#file%
CLOSE #file%
ENDIF

View file

@ -0,0 +1,14 @@
(getFileSize=
size
. fil$(!arg,rb) {read in binary mode}
& fil$(,END) {seek to end of file}
& fil$(,TEL):?size {tell where we are}
& fil$(,SET,-1) {seeking to an impossible position closes the file, and fails}
| !size {return the size}
);
getFileSize$"valid.bra"
113622
getFileSize$"c:\\boot.ini"
211

View file

@ -0,0 +1,16 @@
#include <iostream>
#include <fstream>
std::ios::off_type getFileSize(const char *filename) {
std::ifstream f(filename);
std::ios::pos_type begin = f.tellg();
f.seekg(0, std::ios::end);
std::ios::pos_type end = f.tellg();
return end - begin;
}
int main() {
std::cout << getFileSize("input.txt") << std::endl;
std::cout << getFileSize("/input.txt") << std::endl;
return 0;
}

View file

@ -0,0 +1,19 @@
#include <stdlib.h>
#include <stdio.h>
long getFileSize(const char *filename)
{
long result;
FILE *fh = fopen(filename, "rb");
fseek(fh, 0, SEEK_END);
result = ftell(fh);
fclose(fh);
return result;
}
int main(void)
{
printf("%ld\n", getFileSize("input.txt"));
printf("%ld\n", getFileSize("/input.txt"));
return 0;
}

View file

@ -0,0 +1,13 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
int main(void)
{
struct stat foo;
stat("input.txt", &foo);
printf("%ld\n", foo.st_size);
stat("/input.txt", &foo);
printf("%ld\n", foo.st_size);
return 0;
}

View file

@ -0,0 +1,12 @@
import StdEnv
fileSize fileName world
# (ok, file, world) = fopen fileName FReadData world
| not ok = abort "Cannot open file"
# (ok, file) = fseek file 0 FSeekEnd
| not ok = abort "Cannot seek file"
# (size, file) = fposition file
(_, world) = fclose file world
= (size, world)
Start world = fileSize "input.txt" world

View file

@ -0,0 +1,6 @@
(import '[java.io File])
(defn show-size [filename]
(println filename "size:" (.length (File. filename))))
(show-size "input.txt")
(show-size "/input.txt")

View file

@ -0,0 +1,9 @@
<cfscript>
localFile = getFileInfo(expandpath("input.txt"));
rootFile = getFileInfo("/input.txt");
</cfscript>
<cfoutput>
Size of input.txt is #localFile.size# bytes.
Size of /input.txt is #rootFile.size# bytes.
</cfoutput>

View file

@ -0,0 +1,9 @@
(with-open-file (stream (make-pathname :name "input.txt")
:direction :input
:if-does-not-exist nil)
(print (if stream (file-length stream) 0)))
(with-open-file (stream (make-pathname :directory '(:absolute "") :name "input.txt")
:direction :input
:if-does-not-exist nil)
(print (if stream (file-length stream) 0)))

View file

@ -0,0 +1,5 @@
import std.file;
void main() {
auto len = getSize("data.txt");
}

View file

@ -0,0 +1,35 @@
import std.stdio, std.path, std.file, std.stream;
// NB: mmfile can treat the file as an array in memory
import std.mmfile;
string[] generateTwoNames(string name) {
string cwd = curdir ~ sep; // on current directory
string root = sep; // on root
// remove path, left only basename
name = std.path.getBaseName(name);
// NB: in D ver.2, getBaseName is alias of basename
return [cwd ~ name, root ~ name];
}
void testsize(string fileName1) {
foreach (fileName2; generateTwoNames(fileName1)) {
try {
writefln("File %s has size:", fileName2);
writefln("%10d bytes by std.file.getSize (function),",
std.file.getSize(fileName2));
writefln("%10d bytes by std.stream (class),",
(new std.stream.File(fileName2)).size);
writefln("%10d bytes by std.mmfile (class).",
(new std.mmfile.MmFile(fileName2)).length);
} catch (Exception e) {
writefln(e.msg);
}
writeln();
}
}
void main() {
testsize(r"input.txt");
}

View file

@ -0,0 +1,21 @@
program SizeOfFile;
{$APPTYPE CONSOLE}
uses SysUtils;
function CheckFileSize(const aFilename: string): Integer;
var
lFile: file of Byte;
begin
AssignFile(lFile, aFilename);
FileMode := 0; {Access file in read only mode}
Reset(lFile);
Result := FileSize(lFile);
CloseFile(lFile);
end;
begin
Writeln('input.txt ', CheckFileSize('input.txt'));
Writeln('\input.txt ', CheckFileSize('\input.txt'));
end.

View file

@ -0,0 +1,3 @@
for file in [<file:input.txt>, <file:///input.txt>] {
println(`The size of $file is ${file.length()} bytes.`)
}

View file

@ -0,0 +1,21 @@
class
APPLICATION
create
make
feature {NONE} -- Initialization
make
-- Run application.
do
create input_file.make_open_read ("input.txt")
print(input_file.count)
print("%N")
input_file.close
create environment
input_file.make_open_read(environment.root_directory_name + "input.txt")
print(input_file.count)
input_file.close
end
feature -- Access
input_file: PLAIN_TEXT_FILE
environment:EXECUTION_ENVIRONMENT
end

View file

@ -0,0 +1,16 @@
-module(file_size).
-export([file_size/0]).
-include_lib("kernel/include/file.hrl").
file_size() ->
print_file_size("input.txt"),
print_file_size("/input.txt").
print_file_size(Filename) ->
case file:read_file_info(Filename) of
{ok, FileInfo} ->
io:format("~s ~p~n", [Filename, FileInfo#file_info.size]);
{error, _} ->
io:format("~s could not be opened~n",[Filename])
end.

View file

@ -0,0 +1,24 @@
include file.e
function file_size(sequence file_name)
object x
x = dir(file_name)
if sequence(x) and length(x) = 1 then
return x[1][D_SIZE]
else
return -1 -- the file does not exist
end if
end function
procedure test(sequence file_name)
integer size
size = file_size(file_name)
if size < 0 then
printf(1,"%s file does not exist.\n",{file_name})
else
printf(1,"%s size is %d.\n",{file_name,size})
end if
end procedure
test("input.txt") -- in the current working directory
test("/input.txt") -- in the file system root

View file

@ -0,0 +1,4 @@
"input.txt" file-info size>> .
1321
"file-does-not-exist.txt" file-info size>>
"Unix system call ``stat'' failed:"...

View file

@ -0,0 +1,7 @@
: .filesize ( addr len -- ) 2dup type ." is "
r/o open-file throw
dup file-size throw <# #s #> type ." bytes long." cr
close-file throw ;
s" input.txt" .filesize
s" /input.txt" .filesize

View file

@ -0,0 +1,17 @@
package main
import "fmt"
import "os"
func printFileSize(f string) {
if stat, err := os.Stat(f); err != nil {
fmt.Println(err)
} else {
fmt.Println(stat.Size())
}
}
func main() {
printFileSize("input.txt")
printFileSize("/input.txt")
}

View file

@ -0,0 +1,2 @@
println new File('index.txt').length();
println new File('/index.txt').length();

View file

@ -0,0 +1,5 @@
import System.IO
printFileSize filename = withFile filename ReadMode hFileSize >>= print
main = mapM_ printFileSize ["input.txt", "/input.txt"]

View file

@ -0,0 +1,6 @@
import System.Posix.File
printFileSize filename = do stat <- getFileStatus filename
print (fileSize stat)
main = mapM_ printFileSize ["input.txt", "/input.txt"]

View file

@ -0,0 +1,2 @@
READ(FILE="input.txt", LENgth=bytes) ! bytes = -1 if not existent
READ(FILE="C:\input.txt", LENgth=bytes) ! bytes = -1 if not existent

View file

@ -0,0 +1,3 @@
every dir := !["./","/"] do {
write("Size of ",f := dir || "input.txt"," = ",stat(f).size) |stop("failure for to stat ",f)
}

View file

@ -0,0 +1,2 @@
require 'files'
fsize 'input.txt';'/input.txt'

View file

@ -0,0 +1,10 @@
import java.io.File;
public class FileSize
{
public static void main ( String[] args )
{
System.out.println("input.txt : " + new File("input.txt").length() + " bytes");
System.out.println("/input.txt : " + new File("/input.txt").length() + " bytes");
}
}

View file

@ -0,0 +1,3 @@
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetFile('input.txt').Size;
fso.GetFile('c:/input.txt').Size;

View file

@ -0,0 +1,14 @@
var file = document.getElementById("fileInput").files.item(0); //a file input element
if (file) {
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = loadedFile;
reader.onerror = errorHandler;
}
function loadedFile(event) {
var fileString = event.target.result;
alert(fileString.length);
}
function errorHandler(event) {
alert(event);
}

View file

@ -0,0 +1,2 @@
_size "input.txt"
_size "/input.txt"

View file

@ -0,0 +1,9 @@
'input.txt in current directory
OPEN DefaultDir$ + "/input.txt" FOR input AS #m
PRINT "File size: "; lof(#m)
CLOSE #m
'input.txt in root
OPEN "c:/input.txt" FOR input AS #m
PRINT "File size: "; lof(#m)
CLOSE #m

View file

@ -0,0 +1,9 @@
function GetFileSize( filename )
local fp = io.open( filename )
if fp == nil then
return nil
end
local filesize = fp:seek( "end" )
fp:close()
return filesize
end

View file

@ -0,0 +1,4 @@
d1 = dir('input.txt');
d2 = dir('/input.txt');
fprintf('Size of input.txt is %d bytes\n', d1.bytes)
fprintf('Size of /input.txt is %d bytes\n', d2.bytes)

View file

@ -0,0 +1,3 @@
-- Returns filesize in bytes or 0 if the file is missing
getFileSize "index.txt"
getFileSize "\index.txt"

View file

@ -0,0 +1,2 @@
FileByteCount["input.txt"]
FileByteCount[FileNameJoin[{$RootDirectory, "input.txt"}]]

View file

@ -0,0 +1,4 @@
import java.io.File
puts File.new('file-size.mirah').length()
puts File.new("./#{File.separator}file-size.mirah").length()

View file

@ -0,0 +1,16 @@
MODULE FSize EXPORTS Main;
IMPORT IO, Fmt, FS, File, OSError;
VAR fstat: File.Status;
BEGIN
TRY
fstat := FS.Status("input.txt");
IO.Put("Size of input.txt: " & Fmt.LongInt(fstat.size) & "\n");
fstat := FS.Status("/input.txt");
IO.Put("Size of /input.txt: " & Fmt.LongInt(fstat.size) & "\n");
EXCEPT
| OSError.E => IO.Put("ERROR: Could not get file status.\n");
END;
END FSize.

View file

@ -0,0 +1,4 @@
<?php
echo filesize('input.txt'), "\n";
echo filesize('/input.txt'), "\n";
?>

View file

@ -0,0 +1,3 @@
use File::Spec::Functions qw(catfile rootdir);
print -s 'input.txt';
print -s catfile rootdir, 'input.txt';

View file

@ -0,0 +1,2 @@
(println (car (info "input.txt")))
(println (car (info "/input.txt")))

View file

@ -0,0 +1,4 @@
import os
size = os.path.getsize('input.txt')
size = os.path.getsize('/input.txt')

View file

@ -0,0 +1,2 @@
sizeinwd <- file.info('input.txt')[["size"]]
sizeinroot <- file.info('/input.txt')[["size"]]

View file

@ -0,0 +1,13 @@
/*REXX pgm to verify a file's size (by reading the lines) in CD & root. */
parse arg iFID . /*let user specify the file ID. */
if iFID=='' then iFID='FILESIZ.DAT' /*Not specified? Then use default*/
say 'size of' iFID '=' filesize(iFID) /*current directory.*/
say 'size of \..\'iFID '=' filesize('\..\'iFID) /* root directory.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────FILESIZE subroutine─────────────────*/
filesize: parse arg f
do r=1 while lines(f)\==0
call linein f
end /*r*/
return r-1

View file

@ -0,0 +1,2 @@
size = File.size('input.txt')
size = File.size('/input.txt')

View file

@ -0,0 +1,10 @@
(define (file-size filename)
(call-with-input-file filename (lambda (port)
(let loop ((c (read-char port))
(count 0))
(if (eof-object? c)
count
(loop (read-char port) (+ 1 count)))))))
(file-size "input.txt")
(file-size "/input.txt")

View file

@ -0,0 +1,2 @@
(File name: 'input.txt') size printNl.
(File name: '/input.txt') size printNl.

View file

@ -0,0 +1,2 @@
'input.txt' asFilename fileSize
'/input.txt' asFilename fileSize

View file

@ -0,0 +1,2 @@
file size input.txt
file size /input.txt