2017-11-07 4 views
0

私は586ファイルが.xlsと.xlsx形式のエクセルファイルを持っています。次にshutilを使用して、以下のコードのようにファイルをデスティネーションに転送します。Excelファイルのほんの一部しかコピー先にコピーされていません

import shutil 
import glob 

for filename in glob.glob('C:\\Users\\Documents\\sample_folder\\**\\**', recursive=True): 
    if filename.endswith('.xlsx') or filename.endswith('.xls'): 
    shutil.copy(filename,"C:\\Users\\Documents\\excel-files") 

物事うまくいくと398個のファイルが正常に送信先に転送されますが、私は残りのファイルを得ることはありません、それはあなたが持っているので、shutil.copy()の代わりにshutil.copyfile(src, dst)を使用することを検討して

File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\shutil.py", line 121, in copyfile with open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied: 'C:\Users\Documents\excel-files\XYZ 1310_template.xlsx'

+0

あなたは 'XYZはどこか開い1310_template.xlsx'持っていますか? – DavidG

+0

@DavidG、そうではありません – user8521874

答えて

1

私はあなたのシャトルがかなり確信しています(コードの一部は正しいアプローチではありません)。

Your just trying to copy the filename which is a variable and has names of the files in it.

whereas shutil.copy("src","dest") is required src, is from the source not the filename there.

shutil.copy("src"+filename,"C:\\Users\\Documents\\excel-files") 
1

のようなエラーが表示されますすべてのファイルを書き込む許可。これが動作するかどうか私に教えてください。

それ以外の場合は、指定されたファイルに書き込む権限があるかどうかを確認し、XYZ 1310_template.xlsxファイルなしでプログラムを実行し、これが機能しない唯一のファイルであるかどうかを確認してください。

さらに詳しいヒントは、先に質問したdocumentary またはthat postです。

関連する問題