in reply to Re^2: File::Find stat question
in thread File::Find stat question
I'm still getting a 0 for directory size
Does your script run on a Windows Perl (Strawberry, ActiveState or the like)?
Windows does not have a stat() system call. Perl emulates it, but not perfectly. I assume - without looking at the perl sources - that the struct stat is simply zeroed out and then filled depending on what the Windows API functions return. For directories, size is simply not touched and stays 0.
Note that FAT and NTFS are very different from filesystems found on Unix systems, so having a "size" field for a directory may not make any sense at all.
Also note that the "size" field is not at all related to the size of the files in the directory. On Unix systems, there is -- depending on the filesystem type -- a relation to the highest number of files in the directory over the lifetime of the directory, and maybe the length of the filenames. If you want the sum of the file sizes, calculate it by calling stat for each file in the directory.
POSIX leaves the meaning of the st_size field undefined for directories. It is defined for regular files, symlinks, shared memory objects, and typed memory objects, but not for directories. ("For other file types, the use of this field is unspecified.") So, depending on your operating system, stat() may legally return 0 or just garbage for the size of a directory.
My result for stat on a directory on Win7 NTFS and FAT, Strawberry Perl 5.14.2 is 0, too.
On Linux 3.10.17, perl 5.18.1, ext3, ext2, procfs, sysfs, tmpfs, the results vary from 0 (procfs, sysfs) to 12288 (heavily used directory on ext3), matching the results from ls. The directory size of 0 on procfs is documented in stat(2), sysfs behaves in the same way.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: File::Find stat question
by Anonymous Monk on Nov 27, 2014 at 22:16 UTC | |
by afoken (Chancellor) on Nov 28, 2014 at 04:15 UTC | |
by Anonymous Monk on Nov 30, 2014 at 23:15 UTC |