If I have a path, we say "F:\myfolder\". How do I as simple as possible get maximum folder/file size and how much free space there is on just that path/partition? I know how I can fix this on windows but yeah, it will not be portable which is a requirement, so how are you guys fixing issues as this? I could write a wrapper and use #ifdef WIN32 and such stuff but it would be a ugly solution and besides should it probably fail because I can almost nothing about others operating system than window.
Thanks in advance.
Why do you think portable is even possible? Different OSs (can) use different file systems, so you're probably fresh out of luck. (The best hope I can see is write something for every OS you think probable.)
Portable solution? Sure.
unsigned long long FindMaxFileSize( const std::string &filename )
unsigned long long maxSize = 0;
std::ofstream file( filename.c_str() );
while( file.put( 'x' ) )
remove( filename.c_str() );
Because it sounds like a pretty easy task and I know a OS can use more than one file system. But I will search more.
It was pretty funny.. ;P
I flipped through some of the headers in boost::filesystem, and that seems to do things like that.
Thanks CodeMonekey. The space function in boost.filesystem did fix the job.
And now after some sleep I don't thinks I really need to check max filesize. There is well none modern filesystem that have a smaller max filesize than 2G that the fstream class can handle right?
Probably not. Any filesystem with a smaller limit must either be ancient (i.e., maybe 16-bit DOS?) or for extremely limited devices, I would imagine. I don't think I'd worry too much about the maximum size of a file, as long as you aren't trying to create files larger than 2GB.