2017-01-29 13 views
0

xlsファイルのみを含むフォルダを繰り返し処理していきます。注:すべてのxslファイルは、 "001_text.xls"、... "030_text.xls"のように列挙されます。Python [Errno 2]そのようなファイルやディレクトリがありません

私のコードは次のとおりです。

xls_path=r'C:\path\to\my\folder' 

for file in os.listdir(xls_path): 
    book = xlrd.open_workbook(file) 
    sheet = book.sheet_by_index(0) 

    filt_xls = [ el for el in sheet.col_values(0)] 

    print file.title() 
    print filt_xls 

問題は、私は最初のファイルのみ(001_text.xls)のための出力を得ることで、連続してエラー:

IOError: [Errno 2] No such file or directory: '002_Testo.xls' 

方法にはありますそれを解決する?

+0

フォルダにディレクトリ名を追加するために忘れてしまいました。任意の種類の拡張子を持つ '002_Testo'ファイルは、' -i guess- 'xlrd.open_workbook(file)' '.xls'拡張子を' file'に追加するため、エラーを引き起こす可能性があります。 – Fatih1923

+0

このようなファイルはありますか? –

答えて

1

あなたはおそらく唯一のxlsファイルが含まれている必要があり、各ファイルのパス

import os.path 

for file in os.listdir(xls_path): 
    file = os.path.join(xls_path, file) 
    ..... 
関連する問題