FileTimes 1.9 build: 9470 released: 2008-09-23 Get/Set Windows File Times Create/Modified/Accessed JNI class.. Copyright: (c) 2012 Canadian Mind Products. Java application. Download from: http://mindprod.com/products1.html#FILETIMES ===> Free <=== Full source included. You may even include the source code, modified or unmodified in free/commercial open source/proprietary programs that you write and distribute. May be used freely for any purpose but military. For more details on this restriction, see http://mindprod.com/contact/nonmil.html If you include any Canadian Mind Products code in your own applications, your app too must be labeled non-military use only. All Java jars and source code are included. ---- Prerequisites: This program runs under any OS, (e.g. Win2K/XP/Vista/W7x86/W7-64/OSX/Linux/Solaris/AIX...) so long as you have <><> Java version 1.1 <><> or later installed (32-bit or 64-bit Java). See http://mindprod.com/jgloss/installingjava.html for details. ---- Installing on a PC: Download source and compiled class files to run on your own machine as an application. First install a recent Java JDK or JVM. See http://mindprod.com/jgloss/installingjava.html. To install, extract the zip download with WinZip (or similar unzip utility) into any directory you please, often J:\ -- ticking off the "use folder names" option. To run as an application,type: java -ea -jar J:\com\mindprod\filetimes\filetimes.jar {put any parms here} adjusting as necessary to account for where the jar file is. ---- Installing on a MacIntosh: Use Safari to download source and compiled class files to run on your own machine as an application. Safari will automatically unpack the zip into ~/Downloads (version 10.5) [or on the Desktop (version 10.4 and earlier)]. First install a recent Java JDK or JVM. See http://mindprod.com/jgloss/installingjava.html. You may optionally move the download tree to a permanent home. I don't have a MacIntosh, just a PC, so I can't test my Java programs for Mac compatibility. In theory they should work without problems, but in practice that does not always happen. If you have problems please, let me know, preferably with screenshots and complete verbatim error messages. To run as an application, without parameters, just double click the jar file. To run as an application with parameters, in bash shell type: open Terminal.app cd ~/Desktop java -ea -jar com/mindprod/filetimes/filetimes.jar {put any parms here} adjusting as necessary to account for where the jar file is. ---- Rebuilding: The zip already contains the necessary class and jar files, so unless you modify the program, there is no need to recompile the source or rebuild the jar. Configure.java basedir="E:/" in rebuild.xml to the drive where your files are. Use ANT and rebuild.xml, not build.xml, to recompile and recreate the jar. ---- Use: 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 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 10 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. If you gave me a such a compiler, I could do that for you. For other platforms, you are on your own. I don't have the hardware to write/test such versions. ---- Version History: 1.4 2007-04-26 1.5 2007-05-11 tidy code, add PAD and logo 1.6 2007-06-13 add support for directory times. 1.7 2007-07-28 fix bug, handles not always closed. 1.8 2007-08-30 add TouchDirs, add setFileCreated, setFileLastAccessed, setFileLastModified 1.9 2008-09-23 fix problem with Microsoft C++ auxiliary runtime library. -30-