How to get a directory size

Hello, I'm working on windows 7. I'd like to get some directory size, and when I use the dir commands, I get 0 bytes size.
>> cd 'C:\Users\kr\mother_dir'
>> res = dir
>> res(3).isdir
ans =
1
>> res(3).bytes
ans =
0
Whereas, I'm sure that the size of the son directory called res(3).name is strictly > 0.
Which command should I use please ? Thanks, Karine

Réponses (2)

Titus Edelhofer
Titus Edelhofer le 7 Mai 2012

0 votes

Hi Karine,
you are right, MATLAB does not compute the size of a folder: the bytes for directories are always zero.
You will need to ask the operating system (windows, linux) for the size of a folder ... (or write some function that recursively collects all file sizes).
Titus

1 commentaire

Jan
Jan le 7 Mai 2012
Collecting all files might not be enough. You have to decide, how "size" is defined for hard and soft links, if you consider alternate data streams and if you want the uncompressed size of files, which are compressed by the file system. Another problem is the possibly limited read-access to subfolders. Because this is not trivial and time-consuming, even the opearing systems do not display the folder sizes as default. The determination of the size of all child objects of a folder is such difficult, that I suggest to think twice, if you really need it.

Connectez-vous pour commenter.

Jan
Jan le 7 Mai 2012

0 votes

The size of the directory is in fact 0. I assume you are looking for the size of all recursively contained files. Under *unix this can be determined by "du -sk" and for Windows the function DiskUsage helps: http://technet.microsoft.com/en-us/sysinternals/bb896651.aspx. Both can be called through the system command, but the parsing of the output is not trivial also.

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Question posée :

le 7 Mai 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by