|
-
February 7th, 2005, 07:09 AM
#1
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.
-
February 7th, 2005, 07:47 AM
#2
Re: File sizes
 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.
-
February 7th, 2005, 08:06 AM
#3
Re: File sizes
 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.
-
February 7th, 2005, 08:34 AM
#4
Re: File sizes
Well....you would need to iterate through the directories...
 Originally Posted by Nohero
-
February 10th, 2005, 09:11 AM
#5
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.
-
February 10th, 2005, 09:28 AM
#6
Re: File sizes
Well...you would need to do a string search...
-
February 10th, 2005, 09:29 AM
#7
Re: File sizes
Crap!,
I was hoping there was some quick one-liner out there that could do the job.
Thanks anyway.
Dave.
-
February 10th, 2005, 06:09 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|