How do i use Linux terminal commands like CD and LS?

This question already has an answer here:

  • How do I list all files of a directory? 31 answers

  • 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中自动创建一个列表

    下一篇: 我如何使用Linux终端命令如CD和LS?