|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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" >> |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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! |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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... |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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== |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
RnJvbTogY2xlbWVudC5vd0Bhc2lhLmJucHBhcmliYXMuY29tIA 0KIyBCdXQganVzdCBjdXJpb3Vz
IGFjdHVhbGx5LCB0aGF0IGlmIHRoZXJlIGlzIGFueSBkb2N1bW VudGF0aW9uIHRoYXQgDQojIHBl cnRhaW5zIHRvIHRoZSB3aW4zMm9sZSBtZXRob2RzLCBub3QgdG hlIG9uZSBmcm9tIHRoZSBydWJ5 IA0KDQpjbGVtZW50LCB3aW4zMm9sZSBpcyBtYWlubHkgbWljcm 9zb2Z0LWlzbS4gUnVieSdzIHdp bjMyb2xlIGlzIGp1c3QgYSBiZWF1dGlmdWwgcnVieSB3cmFwcG VyIGZvciB3aW5kb3dzIG9sZS4g WW91J2xsIGhhdmUgdG8gZGlnIHRoZSBtaWNyb3NvZnQgZHNuIH NpdGUgb3IgZG93bmxvYWQgc29t ZSBmcmVlIG9sZSBicm93c2VycyB0byBnZXQgYSBmdWxsIGxpc3 RpbmcvZG9jdW1lbnRhdGlvbiBv ZiB0aGUgb2xlIG1ldGhvZHMgaW4gd2luZG93cy4uLiBZb3UgY2 FuIGNyZWF0ZSB5b3VyIG93biBv bGUgZGxsIGJ1dCB0aGVuIGFnYWluLCB5b3Ugc3RpbGwgaGF2ZS B0byByZWFkIG1pY3Jvc29mdCBz cGVjcyBvbiB0aGF0IHRvby4uLg0KDQpraW5kIHJlZ2FyZHMgLW JvdHANCg== |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
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 thestring 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/. |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|