| | |
file size
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>open the file, seek to end, the get current file position
That's only guaranteed to be meaningful on files opened with a binary orientation. Even then there's a possibility that the size may be inaccurate. The only portable way to determine the working size of a file is to open the file and read it, from beginning to end.
That's only guaranteed to be meaningful on files opened with a binary orientation. Even then there's a possibility that the size may be inaccurate. The only portable way to determine the working size of a file is to open the file and read it, from beginning to end.
I'm here to prove you wrong.
•
•
•
•
Originally Posted by Narue
>oThe only portable way to determine the working size of a file is to open the file and read it, from beginning to end.
Text and binary mode opens are only relevant on MS-DOS/MS-Windows platforms. Other platforms result in identical reads/writes.
>use of standard library file i/o functions are guarenteed by the
>language to be portable across platforms that support them.
And conveniently enough the standard clearly states that arbitrary seeking on a text file is undefined.
>reading the file from beginning to end in MS-Windows will result
>in incorrect file size if the file is opened in text mode.
Perhaps if you want a byte count, but more commonly a character count is what people want. And if they want a byte count, they open the file as binary. So I say again, with complete confidence: The only way to portably get the size of a file is to read it from beginning to end and count what you're looking for.
>language to be portable across platforms that support them.
And conveniently enough the standard clearly states that arbitrary seeking on a text file is undefined.
>reading the file from beginning to end in MS-Windows will result
>in incorrect file size if the file is opened in text mode.
Perhaps if you want a byte count, but more commonly a character count is what people want. And if they want a byte count, they open the file as binary. So I say again, with complete confidence: The only way to portably get the size of a file is to read it from beginning to end and count what you're looking for.
I'm here to prove you wrong.
•
•
•
•
Originally Posted by Narue
>reading the file from beginning to end in MS-Windows will result
>in incorrect file size if the file is opened in text mode.
Perhaps if you want a byte count, but more commonly a character count is what people want. And if they want a byte count, they open the file as binary. So I say again, with complete confidence: The only way to portably get the size of a file is to read it from beginning to end and count what you're looking for.
>Why do you assume you can read people's minds?
I don't assume. That's why I corrected your assumption that an arbitrary seek would work.
>But that is not what "file size" means.
Hypocricy is unbecoming. If you don't see it, allow me to explain. You have no idea what the OP means by "total size of file", and neither do I. The two most likely interpretations are byte count and character count. You assumed byte count, but I didn't assume either and offered a portable solution that worked for both.
I don't assume. That's why I corrected your assumption that an arbitrary seek would work.
>But that is not what "file size" means.
Hypocricy is unbecoming. If you don't see it, allow me to explain. You have no idea what the OP means by "total size of file", and neither do I. The two most likely interpretations are byte count and character count. You assumed byte count, but I didn't assume either and offered a portable solution that worked for both.
I'm here to prove you wrong.
google for "definition of file size" and your definition is not included
http://www.google.com/search?hl=en&l...fine:File+size
http://www.google.com/search?hl=en&l...fine:File+size
•
•
•
•
The amount of space that a file takes up when stored on disk. File size is usally measured in bytes, kilobytes (K), megabytes (MB) or gigabytes (GB).
http://www.bized.ac.uk/educators/16-...p_glossary.htm
>google for "definition of file size" and your definition is not included
Clearly you're not in the right frame of mind to see reason, so I'll waste no more time with you. To keep the thread clean for relevant discussion, please direct any further off-topic comments to my private message box.
Clearly you're not in the right frame of mind to see reason, so I'll waste no more time with you. To keep the thread clean for relevant discussion, please direct any further off-topic comments to my private message box.
I'm here to prove you wrong.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Debugging in VC++ 2005?
- Next Thread: Problem of sorting words of each string using pointers
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






