File Deletion Project

Hey all. I'm a newbie at C++ and hope that you guys can guide me along. I recently got assgined 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. There is a configuration file "config.ini" which looks something like this:

1
2
3
4
5
[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 =). I don't have the code right now so I will post them here tomorrow.

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.

http://www.mediafire.com/download.php?tfmtmnlhgln

Advice or input appreciated, and thanks for taking your time to read this long post.
To delete a file:
BOOL DeleteFile(
LPCTSTR lpFileName
);
As usual for Windows API calls, #include <windows.h>.

If this is a work project, just get an INI parsing library, which should relieve you of some of the work.
I have one here which you can take a look at, but I think it may a) be a little over your head and b) require some modification for your particular needs:
http://onslaught-vn.svn.sourceforge.net/viewvc/onslaught-vn/trunk/src/IO_System/INIfile.h
http://onslaught-vn.svn.sourceforge.net/viewvc/onslaught-vn/trunk/src/IO_System/INIfile.cpp
Hi helios. Thanks for the information.

Can you explain what the Windows API calls & INI parsing library are? I have searched on google but I didn't get a detailed answer. I have also downloaded the files but I don't understand them one bit lol. I thought adding comments to the code might clarify them...

Anyway, here is my current code that I managed to do so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <ctime>
#include <iostream>
#include <fstream>
#include <Windows.h>
#include "IniReader.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;

}


Anyone have ideas on what I should do next?
Topic archived. No new replies allowed.