Solved

How to delete files older than a year in Windows Env. using C++??

Posted on 2003-11-11
6
784 Views
Last Modified: 2010-04-01
I want to write a C++ program to do the following:
1    Check for *.log files in D:\Log directory
2    If there are any *.log files of last year(2002 in this case)  then zip those files.
3    delete the original files which have been zipped in step 2.
4    create a report of how many files totally have been deleted.
5    if any file other than extn .log is present than create a report specyfing that some other file is there.
 
How can I achieve it without much overhead in Windows Environment.
0
Comment
Question by:deepa_pooja
  • 5
6 Comments
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9730756
Firstly using FindFirstFile, FindNextFile you'll get all the files.
0
 
LVL 6

Accepted Solution

by:
GloomyFriar earned 250 total points
ID: 9730770
WIN32_FIND_DATA structure wich is returned by FindFirstFile and FindNextFile contain


ftCreationTime
A FILETIME structure that specifies when the file or directory was created. If the underlying file system does not support creation time, ftCreationTime is zero.

ftLastAccessTime
A FILETIME structure. For a file, the structure specifies when the file was last read from or written to. For a directory, the structure specifies when the directory was created. For both files and directories, the specified date will be correct, but the time of day will always be set to midnight. If the underlying file system does not support last access time, ftLastAccessTime is zero.

ftLastWriteTime
A FILETIME structure. For a file, the structure specifies when the file was last written to. For a directory, the structure specifies when the directory was created. If the underlying file system does not support last write time, ftLastWriteTime is zero.
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9730796
Using these times, you can determine, what files is "old".
To zip those files you need a proper free (or non free) library  - you can search it in the internet.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9730812
The DeleteFile function deletes an existing file.

BOOL DeleteFile(
  LPCTSTR lpFileName   // file name
);
Parameters
lpFileName
[in] Pointer to a null-terminated string that specifies the file to be deleted.
0
 

Author Comment

by:deepa_pooja
ID: 9762765
Imp **
How do I compare the creation time of the file with the system time??
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9764471
Use time conversion functions:

BOOL FileTimeToSystemTime(
  CONST FILETIME *lpFileTime,  // file time to convert
  LPSYSTEMTIME lpSystemTime    // receives system time
);

BOOL SystemTimeToFileTime(
  CONST SYSTEMTIME *lpSystemTime,  // system time
  LPFILETIME lpFileTime            // file time
);

BOOL FileTimeToLocalFileTime(
  CONST FILETIME *lpFileTime,  // UTC file time to convert
  LPFILETIME lpLocalFileTime   // converted file time
);

BOOL LocalFileTimeToFileTime(
  CONST FILETIME *lpLocalFileTime,  // local file time
  LPFILETIME lpFileTime             // file time
);
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question