我有一个文件夹,其中为每个日期创建 json 文件,并为每个小时创建日期。
我可以通过以下方式读取所有文件名:
for root, dirs, files in os.walk(rootdir):
for name in files:
if name.endswith((".json")):
print name
Run Code Online (Sandbox Code Playgroud)
根路径是/home/ubuntu/Desktop/temp/06-56-10/27
在此路径中每个小时都有子文件夹。该子文件夹包含 json 文件。在这里,name打印所有 json 文件名。但它没有给出文件的完整路径,所以我无法读取它。
感谢任何帮助
小智 5
for root, dirs, files in os.walk(rootdir):
for name in files:
if name.endswith((".json")):
print name
full_path = os.path.join(root, name)
Run Code Online (Sandbox Code Playgroud)
完整路径将为您提供文件的完整路径。
| 归档时间: |
|
| 查看次数: |
6942 次 |
| 最近记录: |