반응형
Python을 사용하여 모든 텍스트 파일을 한 폴더에서 다른 폴더로 이동하고 싶습니다. 이 코드를 찾았습니다.
import os, shutil, glob
dst = '/path/to/dir/Caches/com.apple.Safari/WebKitCache/Version\ 4/Blobs '
try:
os.makedirs(/path/to/dir/Tumblr/Uploads) # create destination directory, if needed (similar to mkdir -p)
except OSError:
# The directory already existed, nothing to do
pass
for txt_file in glob.iglob('*.txt'):
shutil.copy2(txt_file, dst)
Blob
폴더의 모든 파일을 이동하고 싶습니다. 오류가 발생하지 않지만 파일이 이동되지 않습니다.
해결 방법
이 시도:
import shutil
import os
source = '/path/to/source_folder'
dest1 = '/path/to/dest_folder'
files = os.listdir(source)
for f in files:
shutil.move(source+f, dest1)
참조 페이지 https://stackoverflow.com/questions/41826868
반응형
'파이썬' 카테고리의 다른 글
파이썬 SSH를 통해 원격 Python 스크립트 실행 (0) | 2020.10.24 |
---|---|
파이썬에서 문자열을 utf-8로 변환하는 방법 (0) | 2020.10.24 |
파이썬 Python의 새 스타일 속성으로 '속성을 설정할 수 없습니다' (0) | 2020.10.24 |
파이썬 Python list sort in descending order (0) | 2020.10.24 |
파이썬 ufunc 'add' did not contain loop with signature matching type dtype ('S32') ('S32') ('S32') (0) | 2020.10.24 |
댓글