touch!!

Remember good old unix/linux command called touch, so simple but very useful, it changes the modified and last access time of a file. Ever felt the need for the same in windows, well I did sometime back.

There is a function in imagehlp.dll which is called TouchFileTimes. This is how we use it…

[sourcecode language=’cpp’]// Include file
#include “Imagehlp.h”

// Link to this library
#pragma comment( lib, “ImageHlp.lib” )

int main( int argc, char **argv )
{
    HANDLE hFile = CreateFile( “C://SomeFile.ext”, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
ASSERT( hFile );

// If second parameter is NULL then system time will be used, or the given date time
    TouchFileTimes( hFile, 0 );
CloseHandle( hFile );

   return 0;
}// End main[/sourcecode]

Output:

Right click and open properties for the file and see what’s the last modified time,
it will be the current system time.

Appreciate your comments...