When doing the project, often to the scene patching, after a period of time, want to put this time out of the patch pack (if every two days out of a patch package) to re-integration, a new patch package out. But how to test the patch package is not a problem, then you have to change the time of the file to a patch package. To find files that have been modified in recent times, it is not an easy thing to see the last modification time of the file in one go. This little thing written today, is to put a certain time after the modified files, all collected, output.
Import Java.io.file;import Java.sql.date;import Java.util.calendar;public class Incrementpackage {public static void Main (string[] args) {Calendar cal = Calendar.getinstance ();//near 10 days Cal.add (Calendar.date,-10);// Modified file name and path Getincrementfile ("D:\\dev_env\\servletjsp\\jase\\src\\com", New Date (Cal.gettimeinmillis ()), modified for nearly 10 days;} /** * Gets the file name modified after the date date in the path directory * @param path PATH * @param date due date */public static void Getincrementfile (String path, Da Te date) {//The file directory is constructed according to the given path FilePath = new file (path);//If the specified file path does not exist, or if there is no file under the folder, return directly if (!filepath.exists () | | | FilePath. Listfiles (). length <= 0) return;//get all Files under File directory file[] files = filepath.listfiles ();//define Last modified time variable date lastmodifiedtime;//traversal file collection for (file file:files) {//If the file is a document, if (File.isfile ()) {//takes out the modified time after the file Lastmodifiedtime = new Date (File.lastmodified ());//compared to the specified cutoff time, if the modification is modified later than the cutoff time if (Lastmodifiedtime.after (date)) {// Output file path and last modified time System.out.println (File.getabsolutepath () + "" + Lastmodifiedtime);}} Do the file is a directory if else if (FILE.ISDIrectory ()) {//Recursive call to Getincrementfile method Getincrementfile (File.getabsolutepath (), date);}}}
Output results
D:\DEV_ENV\servletJsp\Jase\src\com\zhangqi\effective\java\Stack.java 2015-04-24d:\dev_env\servletjsp\jase\src\ Com\zhangqi\exercise\arrsort.java 2015-04-17d:\dev_env\servletjsp\jase\src\com\zhangqi\incrementpackage.java 2015-04-24d:\dev_env\servletjsp\jase\src\com\zhangqi\reg\reg.java 2015-04-15d:\dev_env\servletjsp\jase\src\com\ Zhangqi\xml\xml001.java 2015-04-24d:\dev_env\servletjsp\jase\src\com\zhangqi\you\main\listadd.java 2015-04-24D:\ Dev_env\servletjsp\jase\src\com\zhangqi\you\main\setexec.java 2015-04-18d:\dev_env\servletjsp\jase\src\com\ Zhangqi\you\main\test.java 2015-04-23
Change the entry revision to
Nearly 15 days Cal.add (Calendar.date,-15);
Output results
D:\DEV_ENV\servletJsp\Jase\src\com\zhangqi\compile\ReplaceTest.java 2015-04-10d:\dev_env\servletjsp\jase\src\ Com\zhangqi\effective\java\stack.java 2015-04-24d:\dev_env\servletjsp\jase\src\com\zhangqi\exercise\ Arrsort.java 2015-04-17d:\dev_env\servletjsp\jase\src\com\zhangqi\incrementpackage.java 2015-04-24D:\DEV_ENV\ Servletjsp\jase\src\com\zhangqi\reg\reg.java 2015-04-15d:\dev_env\servletjsp\jase\src\com\zhangqi\reg\ Replacetest.java 2015-04-10d:\dev_env\servletjsp\jase\src\com\zhangqi\xml\xml001.java 2015-04-24D:\DEV_ENV\ Servletjsp\jase\src\com\zhangqi\you\main\datetest.java 2015-04-11d:\dev_env\servletjsp\jase\src\com\zhangqi\you \main\listadd.java 2015-04-24d:\dev_env\servletjsp\jase\src\com\zhangqi\you\main\setexec.java 2015-04-18D:\DEV_ Env\servletjsp\jase\src\com\zhangqi\you\main\test.java 2015-04-23
For the time being, the hidden file is not considered, but the file name and path are output.
There is also a problem to be verified :LastModified Returns the last time the file was modified by this abstract pathname, which is the time the file was modified on the operating system, not the exact time the file was modified. This problem exists in SVN and is later verified.
Returns the list of files modified after a certain time and the modified time