Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 871
  • Last Modified:

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

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
deepa_pooja
Asked:
deepa_pooja
  • 5
1 Solution
 
GloomyFriarCommented:
Firstly using FindFirstFile, FindNextFile you'll get all the files.
0
 
GloomyFriarCommented:
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
 
GloomyFriarCommented:
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
Industry Leaders: 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!

 
GloomyFriarCommented:
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
 
deepa_poojaAuthor Commented:
Imp **
How do I compare the creation time of the file with the system time??
0
 
GloomyFriarCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now