带有文件地址的输出(Python)
我是一名python初学者,我需要帮助解决一个问题。 我需要一个代码,我插入一个文件夹,其中包含jpeg文件,我的输出是文件夹中包含的所有文件的位置地址。 谢谢大家! 谢谢大家。带有文件地址的输出(Python),python,Python,我是一名python初学者,我需要帮助解决一个问题。 我需要一个代码,我插入一个文件夹,其中包含jpeg文件,我的输出是文件夹中包含的所有文件的位置地址。 谢谢大家! 谢谢大家。 import os os.system('cd //add your folder') print(os.system('ls')) 我使用下面的代码得到它: import os path="folder example" for root, dirs, files in os.walk(pat
import os
os.system('cd //add your folder')
print(os.system('ls'))
我使用下面的代码得到它:
import os
path="folder example"
for root, dirs, files in os.walk(path):
print(dirs)
for file in files:
print(os.path.join(root,file)
我建议您查看
os.walk
、string.join
和string.endswith
,因为这些是您可能会使用的方法。祝你好运
import os
path="folder example"
for root, dirs, files in os.walk(path):
print(dirs)
for file in files:
print(os.path.join(root,file)