파이썬

[python] 폴더에서 jpg 파일만 옮기기

Heeyeon Choi 2023. 8. 2. 16:37
728x90
import os
import shutil

f= open("/ssd/crack/data/train.txt","w+")
path = "/ssd/crack/data/train/"

file_lst = os.listdir(path)

for file in file_lst:
    if file.endswith(".jpg"):
        f.write(path+file +"\n")
            
f.close()

- f = open("/ssd/crack/data/train.txt","w+") : train.txt 파일을 쓰기 위해 읽습니다.

- path = "/ssd/crack/data/train/" 불러올 폴더

- if file.endswith(".jpg"): .jpg 로 끝나는 파일이라면,

728x90