How do i use Linux terminal commands like CD and LS?
This question already has an answer here:
Don't execute cd
/ ls
commands for something that exist inside the language library: os.listdir()
.
You can use it like this:
from os import listdir
from os.path import isfile, join
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
Similarly you can use isdir
to check for directories.
You can combine the above commands to make a recursive directory traversal.
链接地址: http://www.djcxy.com/p/20050.html上一篇: 在Python中自动创建一个列表