How can I check if a file exists given a certain base path. I am providing the method a file list for example: file1.snappy, file2,snappy,...
I need to check if file exists in either of the given paths for example: hdfs://a/b/c/source/file1.snappy or if file exists in hdfs://a/b/c/target/file1.snappy. How can I update/modify the method below to accept /a/b/c/target/ or /a/b/c/source/ as a basepath and check if file exists? If it exists in source add to a sourceList and if it is in destination add to a destination list.
val fs = FileSystem.get(sprk.sparkContext.hadoopConfiguration)
def fileExists(fileList:Array[String]) : Boolean = {
var fileNotFound = 0
fileList.foreach{
file => {
if(!fs.exists(new Path(file))) fileNotFound+=1
print("fileList",file)
}
}
if(fileNotFound > 0) {
println(fileNotFound + ": number of files not found probably moved")
false
}
else
true
}
