Can someone please help with the scala equivalent for the below Python code. This code is to recursively list all the files in nested folder present in Azure storage in Databricks.
def deep_ls(path: str):
for x in dbutils.fs.ls(path):
if x.path[-1] is not '/':
yield x
else:
for y in deep_ls(x.path):
yield y
from pprint import pprint
files = list(deep_ls("srcpath/2021/06/16/"))
for x in files:
df = x.name
pprint(df)
Thank you.
The code I have tried:
def deep_ls(path: String) = {
for (x <- dbutils.fs.ls(path)){
if (x.path(-1) != '/') {
return x
}
else{
for (y <- deep_ls(x.path)){
return y
}
}
}
}
The error message.
command-3888229438512929:5: error: method deep_ls has return statement; needs result type
return x
^
command-3888229438512929:8: error: recursive method deep_ls needs result type
for (y <- deep_ls(x.path)){
^
After giving the return type for the function, I am getting the below error.
command-3888229438512929:6: error: type mismatch;
found : com.databricks.backend.daemon.dbutils.FileInfo
required: String
return x
^
command-3888229438512929:10: error: type mismatch;
found : Char
required: String
return y
^
command-3888229438512929:4: error: type mismatch;
found : Unit
required: String
for (x <- dbutils.fs.ls(path)){