Quote:
|
Originally Posted by toe_cutter ls -lh  |
Seeing as this is the C++ forum, that's just a stupid comment.
Only a fool would execute a separate application like ls and use a parser to extract the file size data for what can be done in 10 lines of code.
Nevermind that it's OS specific, succeptable to problems if ls's output changes, etc. So,
Quote:
|
Originally Posted by redhead Or stat() and then use the provided st_size.
But since this can't be dealth with in a ISO/ANSI way, I guess that was the reason I didn't comment on it in the first place... |
That has no relevance to what DJMaze posted or what I responded about.
The purpose of the post was to convert the file size to a human readable number. The structure provided by stat only provides the file size in bytes in the form of the member st_size. It has no bearing whatsoever on the post.
Now, had he said here's an ANSI way to obtain the file size:
Code:
int fileSize(FILE *fp) {
int size=0,c=getc(fp);
for (;c!=EOF;c=getc(fp),size++);
return size;
} Then responding with functions like stat(), GetFileSize(), GetFileSizeEx(), read_vnode() or whatever other OS specific functions would apply would make sense.