Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Pyspark program that interacts with Azure Data Lake Storage Gen 2 using HDFS API. Delete and check operations are demonstrated in this program. You can modify the same to perform all the other file system operations. For more details, refer to
from pyspark.sql import SparkSession
# Author: Amal G Jose
# Reference:
# prepare spark session
spark = SparkSession.builder.appName('filesystemoperations').getOrCreate()
# spark context
sc = spark.sparkContext
# set ADLS file system URI
sc._jsc.hadoopConfiguration().set('fs.defaultFS', 'abfs://')
# FileSystem manager
fs = (
# Enter the ADLS path
path = "Your/adls/path"
# Delete the file or directory in ADLS using the below command
deletion_status = fs.delete(, True)
print("Deletion status -->", deletion_status)
# check whether the file or directory got deleted. This will return True if exists and False if does not
status = fs.exists(
print("Status -->", status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment