crompnk
asked on
Using Python how do you bypass or move an excel file in a folder if it is corrupt?
Hi,
I am using the following Python code in a bigger script, but when some excel files (.xls) are corrupt I get the following error:
raise XLRDError('Unsupported format, or corrupt file: ' + msg)
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'X\xcf\x13\xe0\xa1\xb9\x1 a\xe1'
It fails when opening a workbook that is corrupt (wb = xlrd.open_workbook(filepat h)), which ends the script. Is there a way I can modify the script to bypass the corrupt excel file or move it somewhere else and allow the script to move on?
I am using the following Python code in a bigger script, but when some excel files (.xls) are corrupt I get the following error:
raise XLRDError('Unsupported format, or corrupt file: ' + msg)
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'X\xcf\x13\xe0\xa1\xb9\x1
It fails when opening a workbook that is corrupt (wb = xlrd.open_workbook(filepat
import pandas as pd
import os
import xlrd
import shutil
from os import path
for subdir, dirs, files in os.walk(r'C:\Temp'):
for file in files:
filepath = subdir + os.sep + file
wb = xlrd.open_workbook(filepath)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.