Method: File#size

Defined in:
file.c

#sizeInteger

Returns the size of file in bytes.

File.new("testfile").size   #=> 66

Returns:



2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
# File 'file.c', line 2530

static VALUE
rb_file_size(VALUE obj)
{
    rb_io_t *fptr;
    struct stat st;

    GetOpenFile(obj, fptr);
    if (fptr->mode & FMODE_WRITABLE) {
  rb_io_flush_raw(obj, 0);
    }
    if (fstat(fptr->fd, &st) == -1) {
  rb_sys_fail_path(fptr->pathv);
    }
    return OFFT2NUM(st.st_size);
}