You have my full permission to implement this project any way you please.
I often run bulk processes on files such as:
This will save, for example, spuriouly uploading unchanged files to my website. It will also give me accurate dates an when file content was actually changed.
Every time you run the utility, it recomputes the digests for each file. If they match, it sets the file back to the old date. If they don’t it notes the new timestamp and digest in the people/seal/untouch.digest file.
Tests for file equality compare the file length, then if that matches compare the digest. You don’t need to recompute digests for files whose lengths have not changed or dates have not changed.
It deals with new files and deleted files in the obvious way.
As an add on feature, redate the files back, whether they match or not. This lets you preserve the old dates when there have only been cosmetic changes.
The trickiest part of this project is writing the tiny piece of JNI code to set the date on a file. Unfortunately, this is not supported in pure Java.
You need first to get a handle to the file with the Window’s API CreateFile. This function is misnamed. It does not create a file; it creates a file handle; it opens the file.
| HANDLE CreateFile( | |
| LPCTSTR lpFileName, | // address of name of the file |
| GENERIC_WRITE, | // access (read-write) mode // changing dates is considered writing. |
| FILE_SHARE_READ|FILE_SHARE_WRITE, | // share mode |
| NULL, | // address of security descriptor |
| OPEN_EXISTING, | // how to create |
| 0, | // file attributes |
| NULL | // handle of file with attributes to copy |
| ); |
The SetFileTime function sets the date and time that a file was created, last accessed, or last modified. Java timestamps use 64-bit milliseconds since 1970 GMT. Windows timestamps use 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. Microsoft uses the Gregorian calendar ignoring the missing 12 days between 1752 Sep 2 Wednesday and by 1752 Sep 14 Thursday.
| BOOL SetFileTime( | |
| HANDLE hFile, | // identifies the file |
| CONST FILETIME * lpftCreation, | // time the file was created. little
endian.
// NULL to leave as is. |
| CONST FILETIME * lpftLastAccess, | // time the file was last accessed.
// NULL to leave as is. |
| CONST FILETIME * lpftLastWrite | // time the file was last written. |
| ); |
As you might guess from my detailed instructions, I have written an untouch utility already. Mine uses pure java and supports several command line switches:
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.61] | The information on this page is for non-military use only. | ||
| You are visitor number 1,043. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/project/untouchproj.html | J:\mindprod\project\untouchproj.html | ||