# File.size? incorrect for big files?

**URL:** <https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847>\
**Category:** Ruby\
**Created:** [March 13, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847 "2008-03-13T20:00:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NationS\_Carey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/87869e/32.png) [@NationS\_Carey](https://www.ruby-forum.com/u/NationS_Carey)\
**Post date:** [March 13, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847/1 "2008-03-13T20:00:42Z")

</div>

Hi,

I’ve written a script to monitor some files stored on our network. The  
files range from a few hundred MB to 20-50g. Above a certain point  
which I haven’t really narrowed down yet, the file sizes start being  
reported incorrectly from my script. It’s as if the routine that does  
the system query is using a 32 bit thing for the size and it’s getting  
truncated as integers do. Some files actually come back with a negative  
size. The data type that ruby is using is perfectly capable of holding  
the size of the files. I’ve tried File.size? and FileUtils.size?, so  
I’m somewhat at a loss short of writing an extension. Any ideas?

The script is running on windows, querying the files via UNC paths  
through a samba share on linux.

Thanks!

* * *

Carey Nation [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Lead Software Engineer

CNN BEST

Broadcast Production Systems

Video Solutions Group

(404)827-2935 (wk)

(404)824-0033 (cell)

---

<div class="post-metadata">

**Author:** ![NationS\_Carey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/87869e/32.png) [@NationS\_Carey](https://www.ruby-forum.com/u/NationS_Carey)\
**Post date:** [March 13, 2008, 8:18pm UTC](https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847/2 "2008-03-13T20:18:26Z")

</div>

Some versions, maybe all, of the windows libraries have a bug in  
File.size.  
Make sure you have the latest win32 gems, it seems to help.

The ‘gem outdated’ and ‘gem update’ commands can help.

The only bug I’ve seen is on moderately sized files where the ruby code  
closes the file then immediately checks the file size. It came back as  
zero. I worked around it several versions ago, so my info is not as of  
today.

---

<div class="post-metadata">

**Author:** ![NationS\_Carey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/87869e/32.png) [@NationS\_Carey](https://www.ruby-forum.com/u/NationS_Carey)\
**Post date:** [March 13, 2008, 8:35pm UTC](https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847/3 "2008-03-13T20:35:33Z")

</div>

On Mar 13, 12:59 pm, “Nation, Carey” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m somewhat at a loss short of writing an extension. Any ideas?
> 
> The script is running on windows, querying the files via UNC paths  
> through a samba share on linux.

It’s a bug in Ruby.

The win32-file library fixes it.

require ‘win32/file’ # Do this first  
File.size(some\_big\_file)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![NationS\_Carey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/87869e/32.png) [@NationS\_Carey](https://www.ruby-forum.com/u/NationS_Carey)\
**Post date:** [March 14, 2008, 7:18am UTC](https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847/4 "2008-03-14T07:18:57Z")

</div>

Hi,

At Fri, 14 Mar 2008 03:59:30 +0900,  
Nation, Carey wrote in [ruby-talk:294466]:

> The script is running on windows, querying the files via UNC paths  
> through a samba share on linux.

Microsoft Visual C’s runtime doesn’t support large files, so  
ruby compiled with it also doesn’t. Ruby 1.9 replaces some  
functions to fix it.

---

<div class="post-metadata">

**Author:** ![NationS\_Carey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/87869e/32.png) [@NationS\_Carey](https://www.ruby-forum.com/u/NationS_Carey)\
**Post date:** [March 14, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/file-size-incorrect-for-big-files/131847/5 "2008-03-14T17:09:20Z")

</div>

That did it! Thanks!
