Gets and sets the various Windows file and directory times from Java: create date, last access date and last modified date. Uses JNI and C native code. Create time is when the file was first written. Modified time (sometimes called lastModified) is when the file was last written. Accessed time is when the file was last read or written. Checking its date, looking at its attributes or checking to see if it exists does not count as reading it. Get/Set Windows File Times Create/LastAccessed/LastModified with a JNI native code class. It now also works an directories. Java and JNI you include in your own code. You can test with C: CD \com.mindprod.filetimes java com.mindprod.filetimes.FileTimes This does nothing useful, just exercises the filetimes class. and ensuring nativefiletimes.dll is on the path, e.g. in the current directory. YOU MUST MANUALLY EXTRACT NATIVEFILETIMES.DLL and put it on the path. See http://mindprod.com/jgloss/path.html The key to making FiletTimes work is putting the DLL somewhere on the path or the java library path where Java.exe can find it. See http://mindprod.com/applet/wassup.html if you don't know which directories are suitable homes for the DLL. Download and install wassup. Run it as an application, not an Applet. Check "restricted", and look at the: java.library.path = E:\sys;.;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;F:\Program Files (X86)\jet7.6-pro\bin;E:\Program Files\Java\jdk1.7.0\bin;E:\env;E:\sys;F:\Program Files (x86)\JPSoft\TCMD13;F:\Program Files\vslick\win;F:\Program Files (x86)\apache-ant-1.8.2\bin;F:\Program Files\PostgreSQL\9.0\bin;E:\com\mindprod\reorg;F:\Program Files\TortoiseSVN\bin;F:\Program Files (x86)\asm;F:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\;F:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN;F:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\ These are places you could put the DLL. Your list will be different. Failing that, try putting it on the path. You can also use the ft utility get detailed date/time information about a list of files, e.g. C: CD \com.mindprod.filetimes java com.mindprod.filetimes.FT C:\temp\temp.txt E:\env\bk.bat See FileTimes.java for the API to use these methods in your own programs. FileTimes does nothing by itself, other than a debugging test harness to demonstrate the methods. Windows keeps file timestamps accurate to 100 nanoseconds with 10,000 times as much precision as Java's 1 ms. This means if you copy a file in Java, the new file will not have the exact same timestamp as the old. This package retrieves and sets timestamps accurate only to the millisecond. Beware, virus checker Windows 3000 File System Monitor AMON of NOD32, will interfere with FileTimes and set the file last-Access date to the current time any time you attempt to set it to some value. Other virus checkers might similarly interfere. Vista, by default, to improve performance, does not maintain the last-access-dates of files. You can use the utility fsutil to turn tracking back on. For details, see http://mindprod.com/jgloss/fsutil.html There is also included the TouchDirs utility. You can run it like this java.exe -jar touchdirs.jar C: D: which will modify the last access times of all the directories to the current time. If you immediately subsequently defrag with O&O Defrag with COMPLETE/Access option, it will pull all the directories together, in natural tree order for faster access. TouchDirs cannot modify a read-only directory. To condition your disk for TouchDirs, use the TakeCommand command attrib /D /A:+D /S -r-h *.* to remove the read-only and hidden attributes from your directories. There are also directories that Windows will not let you touch such as X:\System Volume Information C:\Windows\winsxs\* String test file = "C:/temp/somefile"; FileTimes.setFileTimes( testFile, /* set created 2 days ago */ System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000L, /* set accessed 2 hours ago */ System.currentTimeMillis() - 2 * 60 * 60 * 1000L, /* updated 24 hours = 1 day ago */ System.currentTimeMillis() - 24 * 60 * 60 * 1000L ); long current = System.currentTimeMillis(); // do last accessed First, in case others disturb it. long lastAccessed = FileTimes.getFileLastAccessed( testFile ); long created = FileTimes.getFileCreated( testFile ); long lastModified = FileTimes.getFileLastModified( testFile ); Why the three ball C M A icon? It stands for the three timestamps, create, modified and accessed. This program requires modules from the Microsoft C++ Express 9 run time library. Normally they should be automatically statically included. However, if someone recompiled the JNI C++ code without the /MT option, this code will not work unless the vcredist_x86.exe Microsoft C++ Express 11 run time library is preinstalled. You can download it from Microsoft or CMP. see http://mindprod.com/jgloss/cpp.html for details. The symptom of this problem is an UnsatisfiedLinkError or a side-by-side configuration error. Implementation Strategy ----------------------- Before you launch off writing your own code, makes sure the ft and filetimes utilities work. This will ensure you have properly installed the nativefiletimes DLL on the path. Then start with either FT.java or FileTimes.java and gradually modify them a step a time to do what you want in your utility. After every small change, retest them to make sure they work. Don't change the package names of the native code or the JNI code. This JNI code is for 32-bit Javas only. It will not work with 64-bit Java. If you have access to a 64-bit Windows C/C++ compiler to you could modify the C code to produce a 64 bit version. For other platforms, you are on your own. I was unable to figure out why the code does not compile under 64 bit. If you have any ideas what is is upset about, please let me know. The filetimes.64.dll is not provided.