Get absolute paths of all files in a directory

后端 未结 11 2248
一向
一向 2020-12-12 19:00

How do I get the absolute paths of all the files in a directory that could have many sub-folders in Python?

I know os.walk() recursively gives me a list

11条回答
  •  天命终不由人
    2020-12-12 19:24

    Try:

    from pathlib import Path
    path = 'Desktop'
    files = filter(lambda filepath: filepath.is_file(), Path(path).glob('*'))
    for file in files:
       print(file.absolute())
    

提交回复
热议问题