0
0

More than 1 year has passed since last update.

python 自動で拡張子を指定したファイルのみ新規フォルダにコピー -shutil-

Posted at

拡張子を指定したファイルのみ新規フォルダにコピー

import os
import shutil

FOLDER = "コピーした文章" #作成するフォルダ名
if not os.path.exists(FOLDER): #フォルダがない場合作成
    os.mkdir(FOLDER)

for i in os.listdir(): #拡張子を指定して検索、コピー
    if i.endswith(".doc") or i.endswith(".docx"):
        shutil.copy(i, FOLDER+"/"+i)

スクリーンショット 2022-07-11 18.37.49.png
スクリーンショット 2022-07-11 18.38.32.png
スクリーンショット 2022-07-11 18.39.25.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0