使用 Python,我想打印给定目录中的所有文件,而不显示目录本身。我尝试使用 os.walk 但它总是打印目录。
for root, dirs, files in os.walk(directory):
for subFile in files:
print os.path.join(root, subFile)
我使用了目录'DummyFolder/testFolder'
它打印:
DummyFolder/testFolder/folder1/folder2/file.txt
DummyFolder/testFolder/folder1/folder2/file2.txt
DummyFolder/testFolder/folder3/file3.txt
我希望它打印:
folder1/folder2/file.txt
folder1/folder2/file2.txt
folder3/file3.txt
怎么做到呢?
谢谢!