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

답변 (2개)

Titus Edelhofer
Titus Edelhofer 2012년 5월 7일

0 개 추천

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

Jan
Jan 2012년 5월 7일
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.

댓글을 달려면 로그인하십시오.

Jan
Jan 2012년 5월 7일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2012년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by