List of usage examples for org.apache.commons.io.comparator LastModifiedFileComparator LASTMODIFIED_REVERSE
Comparator LASTMODIFIED_REVERSE
To view the source code for org.apache.commons.io.comparator LastModifiedFileComparator LASTMODIFIED_REVERSE.
Click Source Link
From source file:Main.java
public static void main(String[] args) { File dir = new File("c:\\"); File[] files = dir.listFiles(); Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i];/*from ww w . j a v a 2 s . c o m*/ System.out.printf("File %s - %2$tm %2$te,%2$tY%n= ", file.getName(), file.lastModified()); } Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); for (int i = 0; i < files.length; i++) { File file = files[i]; System.out.printf("File %s - %2$tm %2$te,%2$tY%n= ", file.getName(), file.lastModified()); } }
From source file:com.adobe.aem.demo.gui.AemDemoDownload.java
public void run() { if (aemDemo.getDownloadInProgress()) { File theNewestFile = null; File dir = new File(aemDemo.getBuildFile().getParentFile().getAbsolutePath() + File.separator + "dist" + File.separator + "downloads"); FileFilter fileFilter = new WildcardFileFilter("*.*"); File[] files = dir.listFiles(fileFilter); if (files.length > 0) { /** The newest file comes first **/ Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); theNewestFile = files[0];/*from ww w. j ava 2 s . c o m*/ long newSize = theNewestFile.length(); if (newSize != currentSize && (theNewestFile.lastModified() > (System.currentTimeMillis() - 5000))) { System.out.println(" [echo] " + theNewestFile.getName() + " (" + AemDemoUtils.humanReadableByteCount(theNewestFile.length(), true) + ")"); currentSize = newSize; } } } }
From source file:com.adobe.aem.demomachine.gui.AemDemoDownload.java
public void run() { if (aemDemo.getDownloadInProgress()) { File theNewestFile = null; File dir = new File(aemDemo.getBuildFile().getParentFile().getAbsolutePath() + File.separator + "dist" + File.separator + "downloads"); // Folder might have not been created yet if (dir != null && dir.exists()) { FileFilter fileFilter = new WildcardFileFilter("*.*"); File[] files = dir.listFiles(fileFilter); if (files.length > 0) { /** The newest file comes first **/ Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); theNewestFile = files[0]; long newSize = theNewestFile.length(); if (newSize != currentSize && (theNewestFile.getName().indexOf("xml") < 0) && (theNewestFile.getName().indexOf("html") < 0) && (theNewestFile.lastModified() > (System.currentTimeMillis() - 5000))) { System.out.println(" [echo] " + theNewestFile.getName() + " (" + AemDemoUtils.humanReadableByteCount(theNewestFile.length(), true) + ")"); currentSize = newSize; }//from w ww . j av a 2s . c o m } } } }
From source file:fr.fastconnect.factory.tibco.bw.codereview.CodeReviewInitialize.java
public File getTheNewestFile(File directory, String extension) { File newestFile = null;/*from ww w. j a v a2 s .c om*/ if (directory == null || !directory.exists() || !directory.isDirectory()) { return newestFile; } FileFilter fileFilter = new WildcardFileFilter("*." + extension); File[] files = directory.listFiles(fileFilter); if (files.length > 0) { Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); newestFile = files[0]; } return newestFile; }
From source file:com.lightbox.android.bitmap.BitmapFileCleanerTask.java
private static List<File> getFilesSortedByLastModifiedReverse(File dir) { DebugLog.d(TAG, "starting getFilesSortedByLastModifiedReverse"); File[] filesArray = dir.listFiles(); Arrays.sort(filesArray, LastModifiedFileComparator.LASTMODIFIED_REVERSE); DebugLog.d(TAG, "finshed getFilesSortedByLastModifiedReverse"); return Arrays.asList(filesArray); }
From source file:it.baywaylabs.jumpersumo.robot.Daemon.java
/** * This method is called when invoke <b>execute()</b>.<br /> * Do not invoke manually. Use: <i>new Daemon().execute("");</i> * * @param params blank string./*from w w w. j a va 2s. co m*/ * @return null if all is going ok. */ @Override protected String doInBackground(String... params) { while (folder.listFiles().length > 0) { // Select only files, no directory. File[] files = folder.listFiles((FileFilter) FileFileFilter.FILE); // Sorting following FIFO idea. Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); if (files[0].getName().endsWith(".csv") || files[0].getName().endsWith(".txt")) { String commandsList = ""; try { commandsList = f.getStringFromFile(files[0].getPath()); } catch (Exception e) { e.printStackTrace(); } Log.e(TAG, "Lista comandi: " + commandsList); Interpreter in = new Interpreter(deviceController); in.doListCommands(commandsList); files[0].delete(); } else { Log.e(TAG, "Error: There is no csv|txt files or is not a file but a directory."); } } return null; }
From source file:net.sf.jvifm.control.ListFileCommand.java
@SuppressWarnings("unchecked") public void execute() throws Exception { if (pwd == null) return;//from ww w. j av a 2 s . c o m if (pwd.length() == 2 && pwd.endsWith(":")) { pwd = pwd + File.separator; } File currentDir = new File(pwd); String[] filters = cmdLine.getArgs(); OrFileFilter orFileFilter = new OrFileFilter(); if (filters == null || filters.length < 1) { orFileFilter.addFileFilter(new WildcardFileFilter("*")); } else { for (int i = 0; i < filters.length; i++) { orFileFilter.addFileFilter(new WildcardFileFilter(filters[i])); } } if (cmdLine.hasOption("R")) { // FileFinder finder = new FileFinder(); // subFiles = finder.find(currentDir, orFileFilter); } else { subFiles = currentDir.listFiles((FilenameFilter) orFileFilter); } if (cmdLine.hasOption("r")) { if (cmdLine.hasOption("t")) { Arrays.sort(subFiles, LastModifiedFileComparator.LASTMODIFIED_REVERSE); } else if (cmdLine.hasOption("S")) { Arrays.sort(subFiles, SizeFileComparator.SIZE_REVERSE); } else if (cmdLine.hasOption("X")) { Arrays.sort(subFiles, ExtensionFileComparator.EXTENSION_REVERSE); } else { Arrays.sort(subFiles, FileComprator.getFileComprator("name", true)); } } else { if (cmdLine.hasOption("t")) { Arrays.sort(subFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); } else if (cmdLine.hasOption("S")) { Arrays.sort(subFiles, SizeFileComparator.SIZE_COMPARATOR); } else if (cmdLine.hasOption("X")) { Arrays.sort(subFiles, ExtensionFileComparator.EXTENSION_COMPARATOR); } else { Arrays.sort(subFiles, FileComprator.getFileComprator("name", false)); } } listSubFileInPanel(subFiles); }
From source file:com.baasbox.service.dbmanager.DbManagerService.java
public static List<String> getExports() { java.io.File dir = new java.io.File(backupDir); if (!dir.exists()) { dir.mkdirs();/* w ww.ja v a 2s. co m*/ } Collection<java.io.File> files = FileUtils.listFiles(dir, new String[] { "zip" }, false); File[] fileArr = files.toArray(new File[files.size()]); Arrays.sort(fileArr, LastModifiedFileComparator.LASTMODIFIED_REVERSE); List<String> fileNames = new ArrayList<String>(); for (java.io.File file : fileArr) { fileNames.add(file.getName()); } return fileNames; }
From source file:com.cw.litenote.media.image.GalleryGridAct.java
private void getFiles(File[] files) { if (files == null) { Toast.makeText(GalleryGridAct.this, R.string.gallery_toast_no_file, Toast.LENGTH_SHORT).show(); finish();/* ww w . j ava 2 s . c o m*/ } else { // System.out.println("files length = " + files.length); // last one at bottom // Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR); // last one at top Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE); String imagePath[] = new String[files.length]; items = new ArrayList<String>(); fileNames = new ArrayList<String>(); items.add(""); fileNames.add("ROOT"); int i = 0; for (File file : files) { items.add(file.getPath()); fileNames.add(file.getName()); if (UtilImage.hasImageExtension(file.getName(), this)) { // System.out.println("file.getPath() = " + file.getPath()); // System.out.println("i = " + i); if (i < files.length) { imagePath[i] = "file:///" + file.getPath(); System.out.println("imagePath[i] = " + imagePath[i]); i++; } } } mImageUrls = imagePath; } }
From source file:eu.openanalytics.rsb.data.FileResultStore.java
@PreAuthorize("hasPermission(#applicationName, 'APPLICATION_USER')") public Collection<PersistedResult> findByApplicationName(final String applicationName, final String userName) { final File[] resultFiles = getResultsDirectory(applicationName, userName).listFiles(); if ((resultFiles == null) || (resultFiles.length == 0)) { return Collections.emptyList(); }//w w w . ja v a2 s. c o m final Collection<PersistedResult> persistedResults = new ArrayList<PersistedResult>(); final List<File> sortedFiles = new ArrayList<File>(Arrays.asList(resultFiles)); Collections.sort(sortedFiles, LastModifiedFileComparator.LASTMODIFIED_REVERSE); for (final File resultFile : sortedFiles) { final UUID jobId = Util.safeUuidFromString(StringUtils.substringBefore(resultFile.getName(), ".")); if (jobId != null) { persistedResults.add(buildPersistedResult(applicationName, userName, jobId, resultFile)); } } return persistedResults; }