diff --git a/src/main/scala/com/sothr/imagetools/Engine.scala b/src/main/scala/com/sothr/imagetools/Engine.scala index ca71457..4e3ac8e 100644 --- a/src/main/scala/com/sothr/imagetools/Engine.scala +++ b/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] = { 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) + } + } } } }