PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Getting Folder Size
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Getting Folder Size

Réponse
 
LinkBack Outils de la discussion
Vieux 04/07/2008, 08h19   #1
Clement Ow
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Getting Folder Size

When I use File.size("C:/ruby"), all it returns is 0.
But for files it does work fine. So is there a way to calculate folder
size?
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 04/07/2008, 08h48   #2
Torsten Mangner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

Clement Ow wrote:
> When I use File.size("C:/ruby"), all it returns is 0.
> But for files it does work fine. So is there a way to calculate folder
> size?


since a directory is just something virtual, it has a size of 0.

you will have to get all of the files the folder includes (recursive)
and sum their sizes up.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 04/07/2008, 08h53   #3
Torsten Mangner
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

Torsten Mangner wrote:

> since a directory is just something virtual, it has a size of 0.
>
> you will have to get all of the files the folder includes (recursive)
> and sum their sizes up.


or use your operating system to determine the folder size ... like

du -s dir

under unix systems.
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 04/07/2008, 09h06   #4
Clement Ow
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

Torsten Mangner wrote:
> Torsten Mangner wrote:
>
>> since a directory is just something virtual, it has a size of 0.
>>
>> you will have to get all of the files the folder includes (recursive)
>> and sum their sizes up.

>
> or use your operating system to determine the folder size ... like
>
> du -s dir
>
> under unix systems.


I have options that has nonrecursive requirements.. There isnt a direct
method at all that calculates DIR size? Hmmmm, I'm using Windows XP Pro,
so dont suppose the Unix command would work. But, If i use Windows
command, would it probable then?

Cheers
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 05/07/2008, 05h57   #5
Gordon Thiesfeld
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

On Fri, Jul 4, 2008 at 2:06 AM, Clement Ow
<clement.ow@asia.bnpparibas.com> wrote:
> I have options that has nonrecursive requirements.. There isnt a direct
> method at all that calculates DIR size? Hmmmm, I'm using Windows XP Pro,
> so dont suppose the Unix command would work. But, If i use Windows
> command, would it probable then?
>



>> require 'win32ole'

=> true
>> fso = WIN32OLE.new('Scripting.FileSystemObject')

=> #<WIN32OLE:0x2c94060>
>> folder = fso.GetFolder('C:\ruby\scripts')

=> #<WIN32OLE:0x2c90a48>
>> folder.name

=> "scripts"
>> folder.size

=> 226746920
>> folder.path

=> "C:\\ruby\\scripts"
>>


  Réponse avec citation
Vieux 05/07/2008, 19h57   #6
Seebs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

On 2008-07-04, Clement Ow <clement.ow@asia.bnpparibas.com> wrote:
> I have options that has nonrecursive requirements.. There isnt a direct
> method at all that calculates DIR size? Hmmmm, I'm using Windows XP Pro,
> so dont suppose the Unix command would work. But, If i use Windows
> command, would it probable then?


There is no non-recursive solution. There are solutions that put the
recursion in another application, but that's it.

--
Copyright 2008, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
  Réponse avec citation
Vieux 05/07/2008, 22h15   #7
John Joyce
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size


On Jul 5, 2008, at 1:16 PM, Seebs wrote:

> On 2008-07-04, Clement Ow <clement.ow@asia.bnpparibas.com> wrote:
>> I have options that has nonrecursive requirements.. There isnt a
>> direct
>> method at all that calculates DIR size? Hmmmm, I'm using Windows XP
>> Pro,
>> so dont suppose the Unix command would work. But, If i use Windows
>> command, would it probable then?

>
> There is no non-recursive solution. There are solutions that put the
> recursion in another application, but that's it.
>

To explain it a little further... technically, even the system is
doing some recursion here when it shows you a folder size.
Directories don't really have any size to speak of since they are
really just abstract ways to organize data. Doing the recursion is a
good idea. It gives you a chance to get a more accurate result.
Sometimes the system call may be faster though depending on just how
many files are *in* a directory. The system may have some meta data
available already.


  Réponse avec citation
Vieux 06/07/2008, 15h28   #8
Dave Bass
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

John Joyce wrote:
> To explain it a little further... technically, even the system is
> doing some recursion here when it shows you a folder size.


If you right-click on a large Windows folder such as My Documents and
select Properties (in XP at any rate) you can see the system recursing
through and adding up the number of bytes. In theory this figure could
be made available instantly if the system kept track of what was going
on in each folder. But presumably that would slow things down (more).
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 06/07/2008, 15h42   #9
phlip
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

Dave Bass wrote:

> John Joyce wrote:


>> To explain it a little further... technically, even the system is
>> doing some recursion here when it shows you a folder size.

>
> If you right-click on a large Windows folder such as My Documents and
> select Properties (in XP at any rate) you can see the system recursing
> through and adding up the number of bytes. In theory this figure could
> be made available instantly if the system kept track of what was going
> on in each folder. But presumably that would slow things down (more).


Right. In terms of transactions, a file system is a database tuned to rapidly
read and write individual files. Stashing their intermediate sizes - into every
directory entry in a system - would slow down every single write to every file,
and nobody wants that.

Could the original poster attempt what they really need to do, in some other
way? A spot-check of a limited number of file sizes should be relatively cheap...
  Réponse avec citation
Vieux 07/07/2008, 09h23   #10
Clement Ow
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

phlip wrote:
> Dave Bass wrote:
>
>> John Joyce wrote:

>
>>> To explain it a little further... technically, even the system is
>>> doing some recursion here when it shows you a folder size.

>>
>> If you right-click on a large Windows folder such as My Documents and
>> select Properties (in XP at any rate) you can see the system recursing
>> through and adding up the number of bytes. In theory this figure could
>> be made available instantly if the system kept track of what was going
>> on in each folder. But presumably that would slow things down (more).

>
> Right. In terms of transactions, a file system is a database tuned to
> rapidly
> read and write individual files. Stashing their intermediate sizes -
> into every
> directory entry in a system - would slow down every single write to
> every file,
> and nobody wants that.
>
> Could the original poster attempt what they really need to do, in some
> other
> way? A spot-check of a limited number of file sizes should be relatively
> cheap...


Thanks for all your input, guys, really ed me alot! I actually went
along with the WIN32OLE method, which is totally sweet especially when
you have so many options and lines of code is quite hard to implement a
recursive just calculate the file size(i also dont want to compromise on
the efficiency of the script) =) Thanks once again! Really nice workin
with you guys! =D
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 07/07/2008, 10h16   #11
Peña, Botp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

RnJvbTogY2xlbWVudC5vd0Bhc2lhLmJucHBhcmliYXMuY29tIA 0KIyBUaGFua3MgZm9yIGFsbCB5
b3VyIGlucHV0LCBndXlzLCByZWFsbHkgaGVscGVkIG1lIGFsb3 QhIEkgDQojIGFjdHVhbGx5IHdl
bnQgDQojIGFsb25nIHdpdGggdGhlIFdJTjMyT0xFIG1ldGhvZC wgd2hpY2ggaXMgdG90YWxseSBz
d2VldCANCiMgZXNwZWNpYWxseSB3aGVuIA0KIyB5b3UgaGF2ZS BzbyBtYW55IG9wdGlvbnMgYW5k
IGxpbmVzIG9mIGNvZGUgaXMgcXVpdGUgaGFyZCB0byANCiMgaW 1wbGVtZW50IGEgDQojIHJlY3Vy
c2l2ZSBqdXN0IGNhbGN1bGF0ZSB0aGUgZmlsZSBzaXplKGkgYW xzbyBkb250IHdhbnQgdG8gDQoj
IGNvbXByb21pc2Ugb24gDQojIHRoZSBlZmZpY2llbmN5IG9mIH RoZSBzY3JpcHQpID0pIFRoYW5r
cyBvbmNlIGFnYWluISBSZWFsbHkgDQojIG5pY2Ugd29ya2luIA 0KIyB3aXRoIHlvdSBndXlzISA9
RA0KDQppbnRlcmVzdGluZy4gaW1obywgaSBmaW5kIHB1cmUgcn VieSdzIEZpbmQuZmluZCBmYXN0
ZXIsIG1vcmUgZXhwcmVzc2l2ZSwgc2hvcnRlciwgYW5kIHBvcn RhYmxlLCBlZywNCg0KPmRpcnNp
emUgPTANCg0KPkZpbmQuZmluZCgiYzovcnVieTE4NyIpIGRvIH xmfCBkaXJzaXplICs9IEZpbGUu
c3RhdChmKS5zaXplIGVuZA0KIz0+IG5pbA0KDQo+ZGlyc2l6ZQ 0KIz0+IDI0NTY5NzI3DQoNCmFu
IGFkZGVkIGJlYXV0eSBoZXJlIGlzIHRoYXQgeW91IGhhdmUgZ3 JhbnVsYXIgYWNjZXNzIHRvIHRo
ZSBmaWxlcy4gRWcsIHdoYXQgaWYgeW91IHdhbnQgdG8gZ2V0IH RoZSB0b3RhbCBzaXplIG9mIGFs
bCAucmIgYW5kIC5kbGwgZmlsZXM/IHRoYXQgd291bGQgYmUgcGllY2VvZmNha2UgdGhlbi4uLg0K
DQpraW5kIHJlZ2FyZHMgLWJvdHANCg==

  Réponse avec citation
Vieux 07/07/2008, 10h47   #12
Clement Ow
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

Peña, Botp wrote:
> From: clement.ow@asia.bnpparibas.com
> # Thanks for all your input, guys, really ed me alot! I
> # actually went
> # along with the WIN32OLE method, which is totally sweet
> # especially when
> # you have so many options and lines of code is quite hard to
> # implement a
> # recursive just calculate the file size(i also dont want to
> # compromise on
> # the efficiency of the script) =) Thanks once again! Really
> # nice workin
> # with you guys! =D
>
> interesting. imho, i find pure ruby's Find.find faster, more expressive,
> shorter, and portable, eg,
>
>>dirsize =0

>
>>Find.find("c:/ruby187") do |f| dirsize += File.stat(f).size end

> #=> nil
>
>>dirsize

> #=> 24569727



Hmm yea, this is quite an interesting way too, and more handy if you
need to have more options like finding the size or dir count of the
files in a certain directory. It is also easier to modify the code and
get what you want eh? Thanks for the input botp! =) It has been a great
learning experience so far!

But just curious actually, that if there is any documentation that
pertains to the win32ole methods, not the one from the ruby
documentation of WIN32OLE but more of the methods that come along with
it, not really sure how to explain but examples like these:

folder = fso.GetFolder('C:\ruby\scripts')
=> #<WIN32OLE:0x2c90a48>
>> folder.name

=> "scripts"
>> folder.size

=> 226746920
>> folder.path

=> "C:\\ruby\\scripts"

so far I only know of GetFolder,GetFile, name, size, path kinda methods.
just wondering if anyone knows if there is a list of such methods which
might be really ful in manipulating files and folders?

Also, for fso = WIN32OLE.new('Scripting.FileSystemObject')is
FileSystemObject part of ruby? The documentation in ruby states that:
"The first argument should be CLSID or PROGID. If second argument host
specified, then returns OLE Automation object on host." Does anyone know
what this means?

Thanks!

--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 07/07/2008, 10h54   #13
Peña, Botp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

RnJvbTogY2xlbWVudC5vd0Bhc2lhLmJucHBhcmliYXMuY29tIA 0KIyBCdXQganVzdCBjdXJpb3Vz
IGFjdHVhbGx5LCB0aGF0IGlmIHRoZXJlIGlzIGFueSBkb2N1bW VudGF0aW9uIHRoYXQgDQojIHBl
cnRhaW5zIHRvIHRoZSB3aW4zMm9sZSBtZXRob2RzLCBub3QgdG hlIG9uZSBmcm9tIHRoZSBydWJ5
IA0KDQpjbGVtZW50LCB3aW4zMm9sZSBpcyBtYWlubHkgbWljcm 9zb2Z0LWlzbS4gUnVieSdzIHdp
bjMyb2xlIGlzIGp1c3QgYSBiZWF1dGlmdWwgcnVieSB3cmFwcG VyIGZvciB3aW5kb3dzIG9sZS4g
WW91J2xsIGhhdmUgdG8gZGlnIHRoZSBtaWNyb3NvZnQgZHNuIH NpdGUgb3IgZG93bmxvYWQgc29t
ZSBmcmVlIG9sZSBicm93c2VycyB0byBnZXQgYSBmdWxsIGxpc3 RpbmcvZG9jdW1lbnRhdGlvbiBv
ZiB0aGUgb2xlIG1ldGhvZHMgaW4gd2luZG93cy4uLiBZb3UgY2 FuIGNyZWF0ZSB5b3VyIG93biBv
bGUgZGxsIGJ1dCB0aGVuIGFnYWluLCB5b3Ugc3RpbGwgaGF2ZS B0byByZWFkIG1pY3Jvc29mdCBz
cGVjcyBvbiB0aGF0IHRvby4uLg0KDQpraW5kIHJlZ2FyZHMgLW JvdHANCg==

  Réponse avec citation
Vieux 07/07/2008, 11h54   #14
Clement Ow
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size

Peña, Botp wrote:
> From: clement.ow@asia.bnpparibas.com
> # But just curious actually, that if there is any documentation that
> # pertains to the win32ole methods, not the one from the ruby
>
> clement, win32ole is mainly microsoft-ism. Ruby's win32ole is just a
> beautiful ruby wrapper for windows ole. You'll have to dig the microsoft
> dsn site or download some free ole browsers to get a full
> listing/documentation of the ole methods in windows... You can create
> your own ole dll but then again, you still have to read microsoft specs
> on that too...
>
> kind regards -botp


Ah icic. Very interesting indeed.. So to know what to put in the
string after new, WIN32OLE.new('Scripting.FileSystemObject')I have to go
to the microsoft dsn site to see what is in the syntax? Would it be a
universal type of syntax here that can be used with any other types of
programming languages that support WIN32OLE?
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 07/07/2008, 14h38   #15
Daniel Berger
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting Folder Size



On Jul 4, 12:19 am, Clement Ow <clement...@asia.bnpparibas.com> wrote:
> When I use File.size("C:/ruby"), all it returns is 0.
> But for files it does work fine. So is there a way to calculate folder
> size?


Danger: http://blogs.msdn.com/oldnewthing/ar...28/336219.aspx

Regards,

Dan

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h04.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,91150 seconds with 23 queries