파이선 소스 한번 봐주세요 (mp3 파일 이동)
빨간물약님 소스 감사합니다
import os
import shutil
# 이동할 폴더 경로 지정
destination_folder = "/volume1/Music"
# 검색할 폴더 경로 리스트 지정
search_folders = ["/volume2/YouTube/Mortal2244/"]
# 모든 폴더에서 mp3 확장자를 가진 파일 찾기
for search_folder in search_folders:
for filename in os.listdir(search_folder):
if filename.endswith(".mp3"):
file_path = os.path.join(search_folder, filename)
shutil.move(file_path, destination_folder)
Mortal2244/abcd/efg/123.mp3
이런식으로 폴더 안에 폴더가 들어가니 파일을 가져오지 못합니다
수정 부탁드립니다 ..
chat gpt 에게 물어보니
import os
import shutil
# 이동할 폴더 경로 지정
destination_folder = "/volume1/Music"
# 검색할 폴더 경로 리스트 지정
search_folders = ["/volume2/YouTube/Mortal2244/"]
# 모든 폴더에서 mp3 확장자를 가진 파일 찾기
for search_folder in search_folders:
for root, dirs, files in os.walk(search_folder):
for filename in files:
if filename.endswith(".mp3"):
file_path = os.path.join(root, filename)
shutil.move(file_path, destination_folder)
다음에는 chat gpt 에게 물어볼께요 ㅎㅎ
이런 수정은 chatgpt가 잘 해주던 ㅋㅋ
shutil.move(source, destination)
이라고 할때, source나 destination 이나 둘다 전체 경로(파일명을 포함한)를 입력 하셔야 합니다.
코드에서는 file_path만 만드셨어요..
src = os.path.join(원본경로, 파일명)
dst = os.path.join(대상경로, 파일명)
shutil.move(src, dst)
이렇게 수정하시면 문제 없이 되실꺼에요..
조언 감사합니다
cmt alert