I have a ADLS structure as below and I would like to read the files from only the main directory and not the subdirectory. How can I skip the subdirectory in python.
Storage Account
|
|__ sample_container
|
|__main_folder
|
|__ sub_folder
| |
| |__ file1.txt
| |__ file2.csv
| |__ file3.parquet
|
|__ config.txt
|__ data.csv
|__ data1.csv
|__ export.csv
self.container_client = blobservice.get_container_client(container_name)
for files in self.container_client.list_blobs():
print(files)
If I use list_blobs(), it displays directories, sub-directories and files under the container. If I user list_blobs(main_folder), it displays directories, sub-directories and files under the main_folder. This output is as below.
main_folder
main_folder/CONFIG_MASTER.csv
main_folder/LAST_RUN.csv
**main_folder/Sub_folder
main_folder/Sub_folder/sample.csv
main_folder/Sub_folder/example.csv**
main_folder/EXECUTABLE_LOG.csv
main_folder/data_file.csv
main_folder/ProcessControl.csv
Now I only have to read files under main_folder and skip the sub_folder contents. How to achieve this in azure-python SDK?
Also, Is there a way to find out if a blob is a folder or a directory? I am using ADLS gen2 storage.