我想制作一個包含路徑的檔案,但我的問題是路徑的一部分不一樣,例如它還包括不同的白天,這是路徑的一個元素,我不知道如何制作它。我嘗試了不同的方法,但沒有成功。
import os
from pathlib import Path
# example path names after daytime this file incudes aroud 12k files
# path = '/Users/kacper/data_lic/2022-06-10_16-28-28/content_file'
# path = '/Users/kacper/data_lic/2022-09-22_14-20-08/content_file'
for filename in os.listdir(path):
f = os.path.join(path, filename)
if os.path.isfile(f):
out = open('file_paths.txt', 'a') # result file
out.write(f '\n')
out.close()
uj5u.com熱心網友回復:
import glob
path = glob.glob('/Users/kacper/data_lic/*/*') with open('dirs_names.txt', 'w') as
fp: for item in path:
fp.write('%s\n' % item)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/511799.html
標籤:Python文件小路
