Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有文件地址的输出(Python)_Python - Fatal编程技术网

带有文件地址的输出(Python)

带有文件地址的输出(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

我是一名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(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)