File.size() returning negative for large files?

Hi,

I’m getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be
any
size??

I’m using:

  • File.size(path)
  • getting negative number responses for large files (e.g. -1001581 where
    file was really around 3.2GB)
  • using Windows XP
  • using ruby 1.8.5 (2006-08-25) [i386-mswin32]

thanks

Greg H. wrote:

Hi,

I’m getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be
any
size??

I’m using:

  • File.size(path)
  • getting negative number responses for large files (e.g. -1001581 where
    file was really around 3.2GB)
  • using Windows XP
  • using ruby 1.8.5 (2006-08-25) [i386-mswin32]

thanks

It is not yours, but Windows fault.

by

TheR

Hi,

At Sun, 3 Dec 2006 15:56:49 +0900,
Greg H. wrote in [ruby-talk:227857]:

I’m getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be any
size??

I’m using:

  • File.size(path)
  • getting negative number responses for large files (e.g. -1001581 where
    file was really around 3.2GB)
  • using Windows XP
  • using ruby 1.8.5 (2006-08-25) [i386-mswin32]

1.8 series on MS-Windows doesn’t contain large file support.

Is there a work around for this guys?

On Dec 3, 2006, at 24:30 , Greg H. wrote:

It is not yours, but Windows fault.

Is there a work around for this guys?

[-1001581].pack(‘l’).unpack(‘L’).first # => 4293965715


Eric H. - [email protected] - http://blog.segment7.net

A: Yes
Q: Is top-posting bad?
— Derek Milhous Zumsteg

On 12/3/06, Eric H. [email protected] wrote:

  • getting negative number responses for large files (e.g.
    -1001581 where file was really around 3.2GB)

It is not yours, but Windows fault.

Is there a work around for this guys?

[-1001581].pack(‘l’).unpack(‘L’).first # => 4293965715

However, notice that for VERY large files, (larger than 4Gb, I guess,
or 4294967296 bytes), that method fails also

[4294967296].pack(‘l’)

is the same as

[4294967296*2].pack(‘l’)

So something different ought to be used. You might as well get
the info from “system (dir)” or similar for your specific case.

Pedro

excellent!! thanks Eric - who knows how long that would have taken me
to
discover for myself :slight_smile:

On Sun, Dec 03, 2006 at 07:58:19PM +0900, Greg H. wrote:

discover for myself :slight_smile:
Are all your files under 4GB?

Pedro Fortuny A. wrote:

  • File.size(path)
    However, notice that for VERY large files, (larger than 4Gb, I guess,

Pedro

Try ‘Q’ instead. Or, just use win32-file. :slight_smile:

Regards,

Dan

where do you get win32-file? I don’t see it in the api or on the wiki?
Is
it a gem I have to load?

Tks

Greg H. wrote:

  • using Windows XP
  • using ruby 1.8.5 (2006-08-25) [i386-mswin32]

thanks

It’s a bug in Ruby, not Windows. You can use win32-file, which
redefines File.size so that it works properly on Windows.

It uses win32-file-stat behind the scenes, so make sure you’ve got the
latest releases of both win32-file (0.5.2) and win32-file-stat (1.2.3).

Regards,

Dan

Greg H. wrote:

where do you get win32-file? I don’t see it in the api or on the
wiki? Is
it a gem I have to load?
http://rubyforge.org/projects/win32utils/

Greg H. wrote:

where do you get win32-file? I don’t see it in the api or on the wiki? Is
it a gem I have to load?

The gem comes per default with the one click installer. Or, at least, I
see it there and can’t remember installing it :stuck_out_tongue_winking_eye:

David V.