Skip to content

Instantly share code, notes, and snippets.

@glenwatson
Forked from jab416171/listSnippets.java
Last active December 19, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenwatson/5889176 to your computer and use it in GitHub Desktop.
Save glenwatson/5889176 to your computer and use it in GitHub Desktop.
public List<Snippet> listSnippets() throws IOException {
verifyRootDirectoryExists();
File[] txtfiles = DIRECTORY.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile() && !file.isHidden() && file.getName().endsWith(".txt");
}
});
File[] titlefiles = DIRECTORY.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile() && !file.isHidden() && title.getName().endsWith(".title");
}
});
List<Snippet> result = Collections.emptyList();
if(txtfiles != null) {
result = new ArrayList<Snippet>(txtfiles.length);
for (File txtfile : txtfiles) {
Snippet snippet = new Snippet(txtfile);
snippet.setTitle("untitled");
for (File titlefile : titlefiles) {
if(txtfile.getName().substring(0, txtfile.getName().length() - ".txt".length()).equals(titlefile.getName().substring(0, titlefile.getName().length() - ".title".length()))) {
snippet.setTitle(FileUtils.readFileToString(titlefile, CodeSnippetAction.UTF_8));
}
}
result.add(0, snippet);
}
}
Collections.sort(result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment