2

I wish to check if at certain location, say /dbfs/FileStore/tables/xyz.json exists or not. If yes, then the method should return true. I checked method in dbutils but doesn't seem to find any. Plus, I cannot mount any location in ADLS. What are the ways and how can I workaround with it ?

Pankaj Mishra
  • 151
  • 2
  • 10

1 Answers1

1

One way to check is by using dbutils.fs.ls.

Say, for your example.

check_path = 'FileStore/tables/'
check_name = 'xyz.json'

files_list = dbutils.fs.ls(check_path)
files_sdf = spark.createDataFrame(files_list)
result = files_sdf.filter(col('name') == check_name)

Then you can use .count(), or .show(), to get what you want.

For the second question, can you elaborate what you meant by cannot mount?

Spacez
  • 77
  • 2
  • 11