Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List the content of a directory mssparkutils

I used the following code to list the files in a directory but it is showing the entire path instead of just the file name:

historical_logs_adls_path = (
    f"abfss://{staging_container_name}@{staging_account_name}.dfs.core.windows.net/"
    f"{staging_dirname}"
 )


mssparkutils.fs.ls("/")
mssparkutils.fs.ls(historical_logs_adls_path)

I simply need the list of files.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use basename function: https://www.geeksforgeeks.org/python-os-path-basename-method/

Try the below:

import os

historical_logs_adls_path = (
    f"abfss://{staging_container_name}@{staging_account_name}.dfs.core.windows.net/"
    f"{staging_dirname}"
 )

file_list = [os.path.basename(file.path) for file in mssparkutils.fs.ls(historical_logs_adls_path)]
print(file_list)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading