Error when importing from folders

hatstand

Well-known Member
Joined
Mar 17, 2005
Messages
764
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have the following code that simple pulls in the attributes of the files within the folders. I'm doing this so I can read a large number of folders and return their sizes and file sizes etc. The problem I have is that people have saved files with very long file names and so when Power Query tries to read them it returns an error for the particular file. That's not a problem as an Error Query is created and I can correct the files.

My problem is that when analysing a lot of folders it stops at a file that causes an error. I'm at a loss as to how to solve it, but was thinking some kind of IF statement.

Any ideas would be appreciated. I have only just started using Power Query, having moved from using solely VBA.


let
Source = Folder.Files("C:\\MyDocs\Folder1\Folder2"),
#"Expanded Attributes" = Table.ExpandRecordColumn(Source, "Attributes", {"Kind", "Size"}, {"Attributes.Kind", "Attributes.Size"})
in
#"Expanded Attributes"
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
try this
Rich (BB code):
let
   Source = Folder.Files("C:\\MyDocs\Folder1\Folder2"),
   #"Expanded Attributes" = try Table.ExpandRecordColumn(Source, "Attributes", {"Kind", "Size"}, {"Attributes.Kind", "Attributes.Size"}) otherwise "check"
in
   #"Expanded Attributes"

and use code tags [CODE] you code here [/CODE]
 

Watch MrExcel Video

Forum statistics

Threads
1,126,906
Messages
5,621,577
Members
415,846
Latest member
nigeywigey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top