dayjournal memo

Total 975 articles!!

Python #007 - ディレクトリをファイルごと全てコピー

Yasunori Kirimoto's avatar

画像



ディレクトリをファイルごと全てコピーするメモ。


sample.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import shutil


if __name__ == '__main__':

    sample_dir = os.path.exists("./sample")

    if sample_dir == True:
        print ("sampleディレクトリは存在します")
    else:
        shutil.copytree("./sample_moto", "./sample")
        print ("sampleディレクトリをコピーしました")
  


対象ディレクトリでコマンドを実行。


python sample.py


ディレクトリがファイルごとコピーされる。

画像



book

Q&A