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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply

How get all sheet all workbooks folder ? stops at row error "File corrupt"

Power Query M stops at row 310 which shows "DataFormat.Error: File contains corrupted data".

Assuming corruption is from a Workbook, how to get all workbooks w/o fixing corruption?

= Excel.Workbook(File.Contents([Folder Path] & "\" & [Name]), null, true)

 

Thanks to code source 

get-all-sheet-names-from-all-workbooks-in-a-folder 

1 ACCEPTED SOLUTION

This is what I did to solve: Move all non-Excel documents to temporary folder beyond script reach.

I used

robocopy t:\ s:\ /L /S /MOVE /XF *.xl*

which should but didn't catch all png and txt files.

robocopy t:\ d:\ /S /MOVE *.png 

robocopy t:\ d:\ /S /MOVE *.txt

 

Scripting should be capable to exclude non-Excel documents but beyond my current capability.

View solution in original post

4 REPLIES 4

This is what I did to solve: Move all non-Excel documents to temporary folder beyond script reach.

I used

robocopy t:\ s:\ /L /S /MOVE /XF *.xl*

which should but didn't catch all png and txt files.

robocopy t:\ d:\ /S /MOVE *.png 

robocopy t:\ d:\ /S /MOVE *.txt

 

Scripting should be capable to exclude non-Excel documents but beyond my current capability.

You can limit the results to include only Excel files by filtering the Extension column of the table for text that contains xls.

 

jennratten_0-1631761079855.png

 

jennratten
Super User
Super User

This error will be produced when trying to get the content of a file that is encrypted.  I was able to reproduce this error by saving an Excel file and requiring a password.  This error was produced when attempting to read the file from Power Query.

jennratten_0-1631300894676.png

 

You can add a column that tests whether or not the file is accessible, filter out files that are not accessible, and then continue on with your script. In the example below, the files in rows 1 and 3 are not password protected; the file in row 2 is password protected.

 

jennratten_1-1631302520477.png

 

SCRIPT (comments are included to explain what's going on)

let
    Source = Folder.Files("Your folder path goes here"),
    TestEncryption = Table.AddColumn ( 
        Source,
        "isAccessible",
        each 
            let 
                // Use the CSV connector to look at the contents.
                varFile = Csv.Document([Content],[Delimiter=",", Encoding=1252]),
                // Look for a substring that indicates the file is accessible.
                varListOfMatches = List.Select ( varFile[Column1], each Text.Contains ( _, "[Content_Types].xml", Comparer.OrdinalIgnoreCase ) )
            in
                // Does the list have any values (it is not empty)?  yes = accessible, no = unaccessible
                varListOfMatches <> {},
                type logical 
    )
in
    TestEncryption

 

 

 

 

 

Unsucessful delete-hidden-files-that-start-with~ as solution (pointed out by Bob on 2021-04-23 at 19:28 says hidden temporary file with xlsm extension causing query problem.) .  

How to remove files from cmd-dir but not found by cmd-del? Disk Clean-up (Temporary Files same Size afterwards) unable to remove said files. w/o Admin Right to chkdsk NOR Error-Check...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors