Solved

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

Posted on 2003-11-11
6
791 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

685 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