SW/ 개발팁 / 추천프로그램, 꿀팁 공유
  • 돌아가기
  • 아래로
  • 위로
  • 목록
  • 댓글
질문

파이선 소스 한번 봐주세요 (mp3 파일 이동)

지나가는_문과생 지나가는_문과생 259

0

6

빨간물약님 소스 감사합니다 

 

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 

이런식으로 폴더 안에 폴더가 들어가니 파일을 가져오지 못합니다

 

수정 부탁드립니다 .. 

신고공유스크랩
6
profile image 1등
ljr10 2024.04.10. 20:52

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)

profile image
ljr10 2024.04.10. 21:04
지나가는_문과생
chat gpt 가 가끔 잘못된 코드 말해줄때도 있는데 그땐 말로 몇대 때려주면(?) 됩니다
3등
KelvinKang 2024.04.14. 10:21
위 코드로 되시던가요..?

shutil.move(source, destination)
이라고 할때, source나 destination 이나 둘다 전체 경로(파일명을 포함한)를 입력 하셔야 합니다.
코드에서는 file_path만 만드셨어요..

src = os.path.join(원본경로, 파일명)
dst = os.path.join(대상경로, 파일명)
shutil.move(src, dst)

이렇게 수정하시면 문제 없이 되실꺼에요..

댓글 쓰기 권한이 없습니다. 로그인

취소 댓글 등록

cmt alert

신고

"님의 댓글"

이 댓글을 신고하시겠습니까?

댓글 삭제

"님의 댓글"

삭제하시겠습니까?


목록

공유

facebooktwitterpinterestbandkakao story