The documentation say:
File.size(file_name) => integer
Returns the size of file_name.File.size?(file_name) => Integer or
nil Returns nil if file_name doesn‘t
exist or has zero size, the size of
the file otherwise.
On practice (ruby 1.8.7 i386-mswin32):
File.size?('c:/dir')
# => nill
File.size('c:/dir')
# => 0
The nil makes sence for me, but 0? I would expect an exception instead. Do anybody see reason for this?
Directories are files. Well, I suppose in some operating systems they aren’t, but in all Unix-based ones they are.
Of course, in Unix systems, directories in “regular” file systems (i.e., ones that have real files, not
/procor the like) have non-zero size too.