File size

From Rosetta Code
Revision as of 17:27, 25 July 2016 by rosettacode>Gerard Schildberger (added a ;Task: (bold) header, added other whitespace and highlighting to the task's preamble.)
Task
File size
You are encouraged to solve this task according to the task description, using any language you may know.
Task

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.

Ada

<lang ada>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;</lang> Note that reference to the root directory, if there is any, is OS specific.

ALGOL 68

There is no build in way to find the size of an arbitrary file, especially of the file is a special channel, e.g. a tape device.

Conceptually the procedure <lang algol68>PROC set = (REF FILE file, INT page, line, character)VOID: ~ </lang> could be used to do a binary search find the last page's page number. And if it is known that every page has the same number of lines, and every line has the same number of char[s], and the character set is not compressible, then the size could be quickly calculated. Otherwise every page, and every line would have