Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bidev
Frequent Visitor

Gracefully trap Folder Not Found Error

I tried to trap like below, but not working.  Run time error still produced.  Any help would be appreciated.  Thank you.

 

Source = Try Folder.Files("C:\nodirectory"),

output = if Source[HasError] then "Error" else "Good"

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@bidev

Please use the following code .

let
    FolderPath = "C:\nodirectory", 
    Test = try List.Count(Folder.Files(FolderPath)[Content]),
    Source = if Test[HasError] then "Cannot find Data Source" else Folder.Files(FolderPath)
in
    Source



Regards,
Lydia

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@bidev

Please use the following code .

let
    FolderPath = "C:\nodirectory", 
    Test = try List.Count(Folder.Files(FolderPath)[Content]),
    Source = if Test[HasError] then "Cannot find Data Source" else Folder.Files(FolderPath)
in
    Source



Regards,
Lydia

Lydia,

 

Thank you very much for the solution.  It works perfectly!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.