I’m using the readdir method to read a list of files from directories to an array. May I know how to read the zerro size file as the readdir will only read non-zerro file only. I would like to read the empty file as well (capture the file name as treat as exist even it is empty). May I know how to do so? Below is how I read the file from directories:-
opendir (FH, $dirs) || die $! ;
my @lines = readdir (FH) ;
closedir (FH) ;
Thank you in advance.
First of all, you shouldn’t use a bare-word directory handle. Second,
-ztells you when a file is empty. Something like this should work:In fact, as TLP pointed out in the comments, you can use
-sto get the size (in bytes) of the file.