Forum Discussion
Really strange issue - os.listdir
Hi JP8991 ,
When referencing files in the lakehouse Files folder, you do not need to prefix them with /lakehouse/dafault.
As shown below, I have a 2019.csv file in the orders directory under the Files folder. When I reference it in the notebook, the path is as follows:
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
- JP89911 year agoKudo Commander
For the use case I need it for, which is to list what files are listed in a directory, I do not think this is correct.
- Anonymous1 year agoNot applicable
Hi JP8991 ,
You can use this code to list the directories in the Files folder:
import os # set folder path folder_path = "/lakehouse/default/Files/" # list directory try: directories = [d for d in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, d))] # print list for directory in directories: print(directory) except FileNotFoundError: print(f"The directory {folder_path} does not exist.")You can use this code to list the directories in the subfolder orders under the Files folder:
import os # set folder path folder_path = "/lakehouse/default/Files/orders/" # list directory try: directories = [d for d in os.listdir(folder_path) if os.path.isdir(os.path.join(folder_path, d))] # print list for directory in directories: print(directory) except FileNotFoundError: print(f"The directory {folder_path} does not exist.")They all work well.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!- JP89911 year agoKudo Commander
I genuinely think there is some sort of bug.
I ran your code and this was my outcome:
I then ran the code three minutes later and this was my outcome which is exactly as expected: