Get Info for Folder

EZX

Registered
Hi,

I'm trying to get the filesize of a folder including its content. like "get info" from the "File" menu.

I tried NSFileSize, works for files but for folders it only returns the size of the folder itself not including its content.

Does anyone know a way to do this :confused:


Cheers,
Elwin
 
Code:
du -sk [pathname] | awk '{print $1}'

This will print the size of pathname in kilobytes. You can also just do du -sk from the command line to get the size of the current directory. It's very handy. Check out the man page for du if you want more info on this cool utility.
 
Originally posted by davidbrit2
Code:
du -sk [pathname] | awk '{print $1}'
Great, thanks

This is fast :cool: and probably very easy to implement but i just started learning Objective C and i can't seem to figure out how to get your snippet to work in my project.
Can you give me another hint? piece of code? small project :D

I probably need some code to tell my project i'm using DU.

Thanks for your help davidbrit2.

Elwin
 
Hmm, I've never tried reading the output of a UNIX command from a C program, but I'll bet it's quite easy. Since du and awk use stdio, there's probably some means of opening something similar to a file reader that just reads from the commands' standard output. I wish I knew more about how to do this myself, because I could sure put it to use.
 
I got it to work using Applescript's 'do shell script' and mix Applescript with Objective-C.

Not very elegant but it works.

Thanks again,
Elwin
 
There is an Apple sample project called Moriarty which implements a "GUI wrapper around UNIX commands". I had a quick look and it seems to provide a framework for accessing UNIX tasks from Cocoa.

Check it out.
 
I made a AppleScript-Wrapper for: du -sk [pathname] | awk '{print $1}' and it works well.

The next challenge is to invoke the AppleScript from Objective-C.

All examples i found do the opposite, AppleScripts that call Obj-C methods.

:(
 
Back
Top