cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
jonjoseph
Regular Visitor

Fabric Notebook how do I loop files in a folder?

Hi,

So complete newbie to the cloud coming from on premise MS stack.

Trying to put together a PoC end to end.

I have created a lakehouse.

So far I have dumped data from an external system to csv locally.

Plan is to use One lake file explorer to synch files to the cloud.

So now I have a folder with multiple csv files in my lakehouse

I want to use a notebook to read those files and dump them into parquet.

For the life of me I cannot find anything on how to loop the folder, tried os and glob, but I don't know what path to pass in.

Not sure this is the right approach, but the idea is I create a new folder each day of staging data csv files.

Somehow move it to parquet files, and compare the data from the day before to work out whats new and modified.

Then use dbt to transform data and finally load it to datawarehouse.

So back to load the path to loop in the notebook

Thanks

1 ACCEPTED SOLUTION
jonjoseph
Regular Visitor

Copy file API path with os.listdir worked!

View solution in original post

3 REPLIES 3
smpa01
Super User
Super User

@jonjoseph  if I understood correctly, you have this

smpa01_0-1700592675016.png

 

Grab the ABFS path and utilize in the notebook

smpa01_1-1700592830458.png

 

// Replace this with your actual folder path
val files = "abfss://workspace@onelake.dfs.fabric.microsoft.com/testLH2.Lakehouse/Files/DailyFiles"

// Read each CSV file in the folder
val df = spark.read.option("header", "true").csv(files)
.select("*", "_metadata.file_name","_metadata.file_modification_time")

display(df)

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
jonjoseph
Regular Visitor

Copy file API path with os.listdir worked!

Hi @jonjoseph ,

Glad to know your issue got resolved. Please continue using Fabric Community for your further queries.

Helpful resources

Announcements
Sticker Challenge

Join our Community Sticker Challenge

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

JulyFBCVideo

Fabric Monthly Update - July 2024

Check out the July 2024 Fabric update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors