Browse Source

Fixes to NPE errors when searching directories recursively

master
Drew Short 11 years ago
parent
commit
2850c3bf86
  1. 26
      src/main/scala/com/sothr/imagetools/Engine.scala

26
src/main/scala/com/sothr/imagetools/Engine.scala

@ -16,17 +16,21 @@ abstract class Engine extends Logging{
def getAllImageFiles(directoryPath:String, recursive:Boolean=false, recursiveDepth:Int=500):List[File] = { def getAllImageFiles(directoryPath:String, recursive:Boolean=false, recursiveDepth:Int=500):List[File] = {
val fileList = new mutable.MutableList[File]() val fileList = new mutable.MutableList[File]()
val directory:File = new File(directoryPath)
val imageFilter = new ImageFilter
if (directory.isDirectory) {
val files = directory.listFiles(imageFilter)
fileList ++= files
info(s"Found ${files.length} files that are images in directory: $directoryPath")
if (recursive) {
val directoryFilter = new DirectoryFilter
val directories = directory.listFiles(directoryFilter)
for (directory <- directories) {
fileList ++= getAllImageFiles(directory.getAbsolutePath, recursive, recursiveDepth-1)
if (directoryPath != null && directoryPath != "") {
val directory:File = new File(directoryPath)
val imageFilter = new ImageFilter
if (directory.isDirectory) {
val files = directory.listFiles(imageFilter)
if (files != null) {
fileList ++= files
info(s"Found ${files.length} files that are images in directory: $directoryPath")
if (recursive) {
val directoryFilter = new DirectoryFilter
val directories = directory.listFiles(directoryFilter)
for (directory <- directories) {
fileList ++= getAllImageFiles(directory.getAbsolutePath, recursive, recursiveDepth-1)
}
}
} }
} }
} }

Loading…
Cancel
Save