How to write du( disk usage) command

can anyone supply me with some source code about how to write ‘du’?
i need to ge the size of each file in a directory, and sum them up, and
if there are sub-directory, i ned to do it recursively… it seems
can someone help??

My goal is to get the size of a directory, so I can update my RtProgress
during a ‘copy’ command…

Please don’t crosspost.