List files ONLY in the current directory

后端 未结 8 1917
一向
一向 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:01

    import os
    
    destdir = '/var/tmp/testdir'
    
    files = [ f for f in os.listdir(destdir) if os.path.isfile(os.path.join(destdir,f)) ]
    

提交回复
热议问题