Skip to content

Instantly share code, notes, and snippets.

@miyakogi
Created March 28, 2015 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyakogi/6d41191246729d89a602 to your computer and use it in GitHub Desktop.
Save miyakogi/6d41191246729d89a602 to your computer and use it in GitHub Desktop.
Pythonでディレクトリ中のファイルを全て別のディレクトリにSymlinkを辿ってコピー
#!/usr/bin/env python3
import os
import shutil
# コピーしたいディレクトリにいること
# os.getcwd() とか ipythonからならpwdでパス確認できる
# 違うディレクトリにいたら移動するなりソース修正するなり
dstdir = 'コピー先のディレクトリのフルパス'
files = os.listdir()
num_files = len(files) # 進捗表示用
n = 0 # 進捗表示用
for fname in files:
if os.path.isdir(fname): continue # ディレクトリはスキップ
n+=1
print('{}/{}: {}'.format(n, nums, fname))
shutil.copy(fname, dstdir, follow_symlinks=True) # デフォルトTrueですが一応
print('コピー終わりました')
# os じゃなくて pathlib を使ったほうが今風
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment