Forum Discussion
How get all sheet all workbooks folder ? stops at row error "File corrupt"
- 5 years ago
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.
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.
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.
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