/* * [TouchDirs.java] * * Summary: Change the last-accessed time of all dirs on the specified drives to the current time. * * Copyright: (c) 2007-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2007-08-30 Created with IntelliJ IDEA */ package com.mindprod.filetimes; import java.io.File; import java.io.FilenameFilter; import static java.lang.System.*; /** * Change the last-accessed time of all dirs on the specified drives to the current time. *

* When you use O&O defrag COMPLETE/Access defrag, which sorts by access date, * this will pull all the directories together in natural directory * tree order. IT is designed to be just just before an O&O defrag. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2007-08-30 Created with IntelliJ IDEA. * @since 2007-08-30 */ public final class TouchDirs { private static final int FIRST_COPYRIGHT_YEAR = 1997; /** * Undisplayed copyright notice. * * @noinspection UnusedDeclaration */ private static final String EMBEDDED_COPYRIGHT = "Copyright: (c) 1997-2017 Roedy Green, Canadian Mind Products, http://mindprod.com"; /** * Date this version was released to the public. * * @noinspection UnusedDeclaration */ private static final String RELEASE_DATE = "2007-08-30"; /** * Embedded version string. * * @noinspection UnusedDeclaration */ private static final String VERSION_STRING = "1.8"; private static final FilenameFilter ONLY_DIRS_FILTER = new OnlyDirsFilter(); /** * if true we don't emit output */ private static boolean quiet; /** * set lastAccessed date to now of this dir, does not touch subdirs. * * @param dir dir to me modified, */ private static void markAccessed( File dir ) { final String dirname = dir.getAbsolutePath(); final boolean success = FileTimes.setFileLastAccessed( dirname, System.currentTimeMillis() ); if ( success || quiet ) { } else { err.println( "failed to set " + dirname ); } } /** * Recursively touch all directories. * * @param dir root of directory to touch. */ private static void touchDir( File dir ) { if ( dir == null ) { return; } markAccessed( dir ); final String[] subDirsInDir = dir.list( ONLY_DIRS_FILTER ); if ( subDirsInDir != null ) { // can't use for:each since this is JDK 1.1 for ( final String aSubDirsInDir : subDirsInDir ) { // recursive touchDir( new File( dir, aSubDirsInDir ) ); } } } /** * main method * * @param args list of drives to process e.g. "C:" "D:", or -q for quiet mode */ public static void main( String[] args ) { // this is JDK 1.1, can't use for:each for ( final String arg1 : args ) { if ( arg1.equalsIgnoreCase( "-q" ) ) { quiet = true; } else { final File driveAsDir = new File( arg1.charAt( 0 ) + ":/" ); if ( !quiet ) { out.println( "touching drive " + driveAsDir.getAbsolutePath() ); } touchDir( driveAsDir ); } } } } /** * Accept only Directories, no files. We don't use com.mindprod.filter since it requires JDK 1.5 *

* created with Intellij Idea * * @author Roedy Green, Canadian Mind Products */ final class OnlyDirsFilter implements FilenameFilter { /** * Accept only directories to be processed. * * @param dir the directory in which the dir/file was found. * @param name the name of the dir/file * * @return true if and only if the name should be included in the list; false otherwise. */ public boolean accept( File dir, String name ) { final File aFile = new File( dir, name ); return aFile.isDirectory(); } }