CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: File sizes

  1. #1
    Join Date
    Apr 2004
    Posts
    18

    File sizes

    Hi there,
    Im writing a program that creates backups of log files (simply by appending the date and time as a prefix to the log file)

    Another feature I would like is to cap the accumulated files sizes of those logs (in other words the total size of all log files should be no more than 500MB)

    Does anyone have an idea on how I could access the size of each of the logs in a particular directory or location, my program need to be able to run on Win32 and Unix, also I need to be as memory friendly as possible.

    Cheers,
    Dave.

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: File sizes

    Quote Originally Posted by roadragedave
    Does anyone have an idea on how I could access the size of each of the logs in a particular directory or location, my program need to be able to run on Win32 and Unix, also I need to be as memory friendly as possible.
    Win32 and Unix? Well, I guess you can use fseek to move the file pointer at the end and then tell to get the position, which will also be the size of the file in bytes.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Apr 2004
    Posts
    18

    Re: File sizes

    Quote Originally Posted by cilu
    Win32 and Unix? Well, I guess you can use fseek to move the file pointer at the end and then tell to get the position, which will also be the size of the file in bytes.
    This can get me the size of a file to which I already know the title, What if I had a number of logs called FATAL.log, when I preserve the file I call it FATAL.log.07022005.125421 (i.e. FATAL.log.<current date>.<current time>)

    I could have a number of these logs all with a unique prefix, but I dont want the size of the directory to get out of hand, so what I really want is a way of finding all files with the string "FATAL" in their title, and sum up their sizes.

    Cheers,
    Dave.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: File sizes

    Well....you would need to iterate through the directories...
    Quote Originally Posted by Nohero

  5. #5
    Join Date
    Apr 2004
    Posts
    18

    Re: File sizes

    This is great, thanks for the help,
    Also how could I make a comparison of segments of strings, I want to evaluate if a filename contains the string "core", i.e. I have a number of files called "core.120205.135223" & "core.150304.223556" and so on, so what I want is to single out these files.

    Cheers,
    Dave.

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: File sizes

    Well...you would need to do a string search...

  7. #7
    Join Date
    Apr 2004
    Posts
    18

    Re: File sizes

    Crap!,
    I was hoping there was some quick one-liner out there that could do the job.

    Thanks anyway.
    Dave.

  8. #8
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Re: File sizes

    Crap!,
    I was hoping there was some quick one-liner out there that could do the job.
    Well, there is...

    Code:
    std::string str = "core.120205.135223";
    std::string::size_type pos = str.find("core"); // returns std::string::npos
                                                        // if the string is not found
    Old Unix programmers never die, they just mv to /dev/null

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured