내 데이터는 다음과 같이 구성되어 있습니다. 30 개의 폴더가 있습니다. 각각에 3 개의 하위 폴더가 있습니다. 각각에 하나의 파일.파이썬으로 파일에 목록을 쓰는 방법
이 폴더 1의 하위 폴더에있는 파일의 경로를 폴더 1에있는 텍스트 파일 1에 쓰는 스크립트를 작성하고 싶습니다. 다른 모든 폴더에 대해서도 마찬가지입니다.
문제는 스크립트 만, 각 텍스트 파일에, 제 3 파일 (하위 폴더 3 파일)보다는 하위 1, 2의 파일을, 3
이것은 내가 뭘하려 기록이다 :
import glob
import os
gotofolders = '/path/to/folderslocation/'
foldersname = open('/path/to/foldersname.txt').read().split()
for folders in foldersname:
foldersdirectory = os.path.join(gotofolders,foldersname)
filepaths = glob.glob(os.path.join(foldersdirectory)+'*subfolders/*files')
for filepath in filepaths:
savethepaths = os.path.join(foldersdirectory)+'files_path_in_that_folder.txt'
with open (savethepaths,'w') as f:
f.write(filepath+'\n')
마찬가지로 'files_path_in_that_folder.txt'에는 "filepath"목록의 세 번째 요소가 있는데,이 요소는 모두 3 가지 요소가 아닙니다.
감사합니다.