Solved

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

Posted on 2003-11-11
6
750 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
Comment Utility
Firstly using FindFirstFile, FindNextFile you'll get all the files.
0
 
LVL 6

Accepted Solution

by:
GloomyFriar earned 250 total points
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:GloomyFriar
Comment Utility
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
Comment Utility
Imp **
How do I compare the creation time of the file with the system time??
0
 
LVL 6

Expert Comment

by:GloomyFriar
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now