How to check if a file size is greater than a determined number? [duplicate]
-
11-06-2021 - |
質問
I want to use a if statement to check if a file size is greater than a determined number in kb. For example:
if(filesize GTREATER than VARX){
DO
}else{
DO
}
I'm new to C yet, so please, can you explain clearly, if I have to use a different function.
解決
If you've already fopen()
ed the file, then you can use fstat()
. stat()
or lstat()
can be used on files by name (in a string), but are somewhat less efficient if you do it repeatedly. You'll need to use fileno()
to get the file descriptor (int
) from the FILE *
returned by fopen()
. Otherwise, the man pages have reasonable examples.
所属していません StackOverflow