Recursive File Listing (Java)
package com.harris.fdca;

import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.io.*;

public class RecursivePdfFileSize {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		if (args.length == 0) {
			System.err.println("Need path");
			System.exit(1);
		}
		File root = new File(args[0]);
	
		try {
		    String[] extensions = null;
		    boolean recursive = true;
		
		    //
		    // Finds files within a root directory and optionally its
		    // sub-directories which match an array of extensions. When the
		    // extensions is null all files will be returned.
		    //
		    // This method will returns matched file as java.io.File
		    //
		    Collection files = FileUtils.listFiles(root, extensions, recursive);
		    
		    for (Iterator iterator = files.iterator(); iterator.hasNext();) {
		        File file = (File) iterator.next();
		        System.out.println(file.getAbsolutePath()+"\t"+file.length());
		    }
		} catch (Exception e) {
		    e.printStackTrace();
		}
	}

}

recursivefilelist.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0