Click to See Complete Forum and Search --> : File sizes
roadragedave
February 7th, 2005, 06:09 AM
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.
cilu
February 7th, 2005, 06:47 AM
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.
roadragedave
February 7th, 2005, 07:06 AM
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.
Andreas Masur
February 7th, 2005, 07:34 AM
Well....you would need to iterate through the directories...
A Linux solution (http://www.codeguru.com/forum/showthread.php?t=285893)
A windows solution (http://www.codeguru.com/forum/showthread.php?t=312461)
roadragedave
February 10th, 2005, 08:11 AM
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.
Andreas Masur
February 10th, 2005, 08:28 AM
Well...you would need to do a string search...
roadragedave
February 10th, 2005, 08:29 AM
Crap!,
I was hoping there was some quick one-liner out there that could do the job.
Thanks anyway.
Dave.
HighCommander4
February 10th, 2005, 05:09 PM
Crap!,
I was hoping there was some quick one-liner out there that could do the job.
Well, there is...
std::string str = "core.120205.135223";
std::string::size_type pos = str.find("core"); // returns std::string::npos
// if the string is not found
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.