Thread: Filesystem information

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    40

    Filesystem information

    Hi, all!
    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.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.)

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Portable solution? Sure.

    Code:
    unsigned long long FindMaxFileSize( const std::string &filename )
    {
        unsigned long long maxSize = 0;
        {
            std::ofstream file( filename.c_str() );
            while( file.put( 'x' ) )
                ++maxSize;
        }
        remove( filename.c_str() );
        return maxSize;
    }
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    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.

    brewbuck
    It was pretty funny.. ;P


    Thanks anyway.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    I flipped through some of the headers in boost::filesystem, and that seems to do things like that.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    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?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. C Library For Filesystem information?
    By Newmer60 in forum C Programming
    Replies: 2
    Last Post: 06-27-2008, 11:12 AM
  3. Assignment Help !! (Student information system)
    By ashb in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 05:32 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM