Convert GNU find command to Python function
I want to convert this GNU command into a python function:
find folder/ 2>/dev/null > file.txt
The find will list all files and folders fr开发者_开发知识库om the directory recursively and write them to a file.
What I have now in Python is:
import os
project="/folder/path"
i=0
for (project, dirs, files) in os.walk(project):
print project
print files
i += 1
But now I am trying to make the output exactly as find does.
import os
path = "folder"
for dirpath, dirnames, filenames in os.walk(path):
print(dirpath)
for filename in filenames:
print(os.path.join(dirpath, filename))
Instead of print
you can write to file.
精彩评论