Python program to traverse directories and read file information

后端 未结 3 2146
感动是毒
感动是毒 2021-02-19 16:23

I\'m just getting started with Python but already have found it much more productive than Bash shell scripting.

I\'m trying to write a Python script that will traverse e

3条回答
  •  不要未来只要你来
    2021-02-19 17:04

    Try

    info = []
    for path, dirs, files in os.walk("."):
        info.extend(FileInfo(filename, path) for filename in files)
    

    or

    info = [FileInfo(filename, path)
            for path, dirs, files in os.walk(".")
            for filename in files]
    

    to get a list of one FileInfo instance per file.

提交回复
热议问题