--------------------------------------------------------------------------------
Hey all. I'm a newbie at C++ and hope that you guys can guide me along. I recently got assigned a project and is needed to code it in C++, which I have almost zero experience with, so bear with me. =)
I need to delete 3 log files from a particular location. The name of the 3 files include (name + date + extension)where the name could be changed in a particular ini file named "config.ini". The configuration file look something like this:
[config]
PATH = C:\\Test\\
LOG1 = ABC
LOG2 = XYZ
DB = DATA
LOG1 and LOG2 needs to be on yesterday's date. An example would be "ABC090420.txt". DB needs to be the date when it was eight days ago.
I want to be able to change the path where the file is located and the name of the files at will in the "config.ini". Whether the files are deleted or not, it will be recorded in a newly created text file "LogDelete.txt". The program will run once every week, which means the "LogDelete.txt" will keep appending data without overwriting previous weeks' record.
I have completed the date part (getting yesterday and eight days ago date) and the "LogDelete.txt" thanks to Google =).
My request now is to have someone guide me along as to what I am suppose to do and give me a brief idea of how the syntax of each particular steps will look like. I am not asking for anyone to write the entire code for me, because I want to learn this and do it by my own effort if possible.
I am currently running on Windows XP and using Dev-C++.
If anyone wants a sample of how the program looks like, I have a jar file which I have completed previously but got rejected. You need java runtime to run the jar file. Attachment is below.
Advice or input appreciated, and thanks for taking your time to read this long post. Below is what I have gotten thus far:
#include <ctime>
#include <iostream>
#include <fstream>
#include <Windows.h>
using namespace std;
int main(int argc, char *argv[])
{
time_t today, ytd, eightDays, currTime;
struct tm * timeinfo;
int year, month, day;
char yest [10];
char eight [10];
time (&currTime);
cout << ctime(&currTime) << endl;
time( &today );
timeinfo = localtime ( &today );
ytd = today - 86400;
timeinfo = localtime (&ytd);
strftime (yest, 10, "%y%m%d", timeinfo);
eightDays = today - 691200;
timeinfo = localtime (&eightDays);
strftime (eight, 10, "%y%m%d", timeinfo);
cout << "Yesterday = " << yest << endl;
cout << "Eight Days ago = " << eight << endl;
FILE * aFile;
aFile = fopen("LogDelete.txt", "a+");
if (aFile!=NULL) {
ofstream aFile ( "LogDelete.txt", ios::app );
aFile << "Program run time: " << ctime(&currTime) << endl;
aFile.close();
}
cin.get();
return 0;
}