Difference between revisions of "Determine the size of a file"

From CodeCodex

(highlightsyntax => pre)
(Erlang)
Line 10: Line 10:
 
> (with-open-file (file "output.swf") (file-length file))
 
> (with-open-file (file "output.swf") (file-length file))
 
193842
 
193842
 +
</pre>
 +
 +
===Erlang===
 +
<pre>
 +
filelib:file_size(Filename).
 
</pre>
 
</pre>
  
Line 62: Line 67:
 
[[Category:Bash]]
 
[[Category:Bash]]
 
[[Category:Common Lisp]]
 
[[Category:Common Lisp]]
 +
[[Category:Erlang]]
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:Perl]]
 
[[Category:Perl]]

Revision as of 18:39, 24 December 2010

Implementations

Bash

$ wc -c filename

Common Lisp

Quite easy with Common Lisp:

> (with-open-file (file "output.swf") (file-length file))
193842

Erlang

filelib:file_size(Filename).

Java

    File file = new File("infilename");
    
    // Get the number of bytes in the file
    long length = file.length();

Perl

my $file_size = -s 'filename';

PHP

$file_size = filesize('filename');

Python

TheFileSize = os.path.getsize(TheFileName)

Ruby

size = File.size(file_name)

Seed7

size := fileSize(file_name);

Tcl

proc filesize f {
  file stat $f a
  return $a(size)
}

Zsh

zmodload -i zsh/stat
zstat +size filename