[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File#size

Roger Pack

2/7/2009 2:27:00 PM

I am thinking this would be a nice function to have in the stdlib.

File#size

thoughts?
-=r
--
Posted via http://www.ruby-....

9 Answers

Robert Klemme

2/7/2009 2:53:00 PM

0

On 07.02.2009 15:26, Roger Pack wrote:
> I am thinking this would be a nice function to have in the stdlib.
>
> File#size
>
> thoughts?

Others seems to agree

http://www.ruby-doc.org/core/classes/File.ht...

robert

David A. Black

2/7/2009 3:10:00 PM

0

Hi --

On Sat, 7 Feb 2009, Robert Klemme wrote:

> On 07.02.2009 15:26, Roger Pack wrote:
>> I am thinking this would be a nice function to have in the stdlib.
>>
>> File#size
>>
>> thoughts?
>
> Others seems to agree
>
> http://www.ruby-doc.org/core/classes/File.ht...

I think Roger means an instance method.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.r...
Coming in 2009: The Well-Grounded Rubyist (http://manning....)

http://www.wis... => Independent, social wishlist management!

Dylan Evans

2/7/2009 3:10:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

How about file.stat.size ?

On Sun, Feb 8, 2009 at 12:26 AM, Roger Pack <rogerpack2005@gmail.com> wrote:

> I am thinking this would be a nice function to have in the stdlib.
>
> File#size
>
> thoughts?
> -=r
> --
> Posted via http://www.ruby-....
>
>


--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Roger Pack

2/7/2009 3:35:00 PM

0

Dylan Evans wrote:
> How about file.stat.size ?

ooh that's really close.
I might want one that takes into account unflushed buffers, though.
Apparently .stat.size doesn't quite.

>> a.write 'abc'
=> 3
>> a.stat.size
=> 0
>> a.flush
=> #<File:README>
>> a.stat.size
=> 3

But at least it's pretty close.
-=r
--
Posted via http://www.ruby-....

Dylan Evans

2/7/2009 3:48:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

I didn't know that, but it's something to bear in mind. I haven't read the
code but i suspect that it is a shortcut for File::Stat.new('file').size


On Sun, Feb 8, 2009 at 1:34 AM, Roger Pack <rogerpack2005@gmail.com> wrote:

> Dylan Evans wrote:
> > How about file.stat.size ?
>
> ooh that's really close.
> I might want one that takes into account unflushed buffers, though.
> Apparently .stat.size doesn't quite.
>
> >> a.write 'abc'
> => 3
> >> a.stat.size
> => 0
> >> a.flush
> => #<File:README>
> >> a.stat.size
> => 3
>
> But at least it's pretty close.
> -=r
> --
> Posted via http://www.ruby-....
>
>


--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Robert Klemme

2/7/2009 4:30:00 PM

0

On 07.02.2009 16:34, Roger Pack wrote:
> Dylan Evans wrote:
>> How about file.stat.size ?
>
> ooh that's really close.
> I might want one that takes into account unflushed buffers, though.
> Apparently .stat.size doesn't quite.
>
>>> a.write 'abc'
> => 3
>>> a.stat.size
> => 0
>>> a.flush
> => #<File:README>
>>> a.stat.size
> => 3
>
> But at least it's pretty close.
> -=r

So you want to know how much you have written? Then use #tell
http://www.ruby-doc.org/core/classes/IO.ht...

robert

Roger Pack

2/7/2009 5:16:00 PM

0

> So you want to know how much you have written? Then use #tell
> http://www.ruby-doc.org/core/classes/IO.ht...
>
> robert

It appears that #tell gives you the size of the file you're writing to,
and File#stat.size tells you the filesize of files you're reading from,
is that right?
--
Posted via http://www.ruby-....

Tim Hunter

2/7/2009 8:18:00 PM

0

Roger Pack wrote:
>> So you want to know how much you have written? Then use #tell
>> http://www.ruby-doc.org/core/classes/IO.ht...
>>
>> robert
>
> It appears that #tell gives you the size of the file you're writing to,
> and File#stat.size tells you the filesize of files you're reading from,
> is that right?

#tell tells you where you're at in the file, not the size of the file.
If you're in the middle of reading a file, #tell tells you how far you
are from the start of file. If you seek to offset 100 in a 100,000 byte
file, #tell returns 100, not 100,000.

$ ri IO#tell
---------------------------------------------------------------- IO#tell
ios.pos => integer
ios.tell => integer
------------------------------------------------------------------------
Returns the current offset (in bytes) of ios.

f = File.new("testfile")
f.pos #=> 0
f.gets #=> "This is line one\n"
f.pos #=> 17


--
RMagick: http://rmagick.ruby...

Lars Haugseth

2/11/2009 3:18:00 PM

0

* "David A. Black" <dblack@rubypal.com> wrote:
>
> Hi --
>
> On Sat, 7 Feb 2009, Robert Klemme wrote:
>
> > On 07.02.2009 15:26, Roger Pack wrote:
> >> I am thinking this would be a nice function to have in the stdlib.
> >>
> >> File#size
> >>
> >> thoughts?
> >
> > Others seems to agree
> >
> > http://www.ruby-doc.org/core/classes/File.ht...
>
> I think Roger means an instance method.

There are many other File class methods for which it would be convenient
to have instance method counterparts. This and much more can be found in
the standard library Pathname:

http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pat...

--
Lars Haugseth

"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer