Guest

ScriptScannerTest.java

By: a guest on Jun 14th, 2010  |  syntax: Java 5  |  size: 1.08 KB  |  hits: 170  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. import java.io.IOException;
  2. import java.io.File;
  3.  
  4. public class ScriptScannerTest {
  5.  
  6.         public static void main(String[] args) throws IOException {
  7.                 File startPath = new File("C:\\Users\\Gary\\Desktop\\Trek\\");
  8.                 System.out.println("File,Line,Keyword,Value");
  9.                 visitAllDirsAndFiles(startPath);
  10.         }
  11.          
  12.         private static void visitAllDirsAndFiles(File dir) throws IOException {
  13.                 // Process all files and directories under dir
  14.                 // Thanks to: http://www.exampledepot.com/egs/java.io/TraverseTree.html
  15.             if (!dir.isDirectory()) {
  16.                 // scan this file
  17.                 String filePath = dir.getAbsolutePath();
  18.                 if (filePath.matches(".*txt$")) {
  19.                                 String contents = ScriptScanner.getFileContents(filePath);
  20.                                 contents = ScriptScanner.stripFileContents(contents);
  21.                                 ScriptScanner.scanFor(filePath, contents, "heading", "bearing", "mark", "range", "sector");
  22.                 }
  23.             }
  24.  
  25.             if (dir.isDirectory()) {
  26.                 String[] children = dir.list();
  27.                 for (int i=0; i<children.length; i++) {
  28.                     visitAllDirsAndFiles(new File(dir, children[i]));
  29.                 }
  30.             }
  31.         }
  32.        
  33. }