os.walk
을 사용하면 전체 디렉토리 목록을 가져와이 목록을 사용하여 모든 파일을 반복적으로 복사 할 수 있습니다. 또한 MatthewFranglen
년대에 따라
file_paths = [os.path.join(root, f) for root, _, files in os.walk('.') for f in files]
for path in file_paths:
print path
shutil.copy(path, target)
같은 뭔가 그냥 shutil.copytree(src, dst)
을 할 수있는 코멘트. 그것은 또한 당신이 일을 무시하도록 허락 할 것이지만, 당신은 목록 이해에 if를 사용하는 대신에 그것을 수행하는 함수를 정의 할 필요가있을 것이다.
# ignore all .DS_Store and *.txt files
file_paths = [os.path.join(root, f) for root, _, files in os.walk('.') for f in files if (f != '.DS_Store') or f.endswith('.txt'))]
는 cp``에`-v` 스위치를 추가하고 모든 파일이 복사가 표시됩니다
from shutil import copytree, ignore_patterns
ignore_func = ignore_patterns('.DS_Store', '*.txt') # ignore .DS_Store and *.txt files
copytree('/path/to/dir/', '/other/dir', ignore=ignore_func)
에 비교했다. – ThiefMaster
'os.walk'과'shutil.copy'를 사용할 수 있습니다. – Blender
-v verbose 옵션을 사용하면 충분하지 않습니다. 파일 이름 – jviotti