List files ONLY in the current directory

后端 未结 8 1904
一向
一向 2020-11-28 00:09

In Python, I only want to list all the files in the current directory ONLY. I do not want files listed from any sub directory or parent.

There do seem to be similar

8条回答
  •  抹茶落季
    2020-11-28 01:02

    You can use the pathlib module.

    from pathlib import Path
    x = Path('./')
    print(list(filter(lambda y:y.is_file(), x.iterdir())))
    

提交回复
热议问题