lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Index all the files in a directory
Date Wed, 19 Apr 2006 19:06:06 GMT
Maybe something like this will work.... It just recursively descends from
the root passed to parseAll, processing each .txt file it finds.


    // Parameter is just the file path of the parent directory.
    public void parseAll(String sParentDir) throws Exception {
        indexTree(new File(sParentDir));
    }

    private void indexTree(File file) throws Exception {
        if (file.canRead()) {
            if (file.isDirectory()) {
                String[] files = file.list();
                if (files != null) {
                    for (int idx = 0; idx < files.length; idx++) {
                        indexTree(new File(file, files[idx]));
                    }
                }
            } else {
                if (file.getName().toLowerCase().indexOf(".txt") == -1)
                    return;
                try {
                    index your file here.
                } catch (Exception e) {
                    handle error here.
            }
        }
    }



Erick

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message