Search code examples
pythonpython-3.8python-oslistdir

how to get rid of desktop.ini with python's os.listdir() method of any windows folder


I'm using windows server 2016. I didn't have this issue earlier. I get the desktop.ini file listed when I run the command below.

import os
os.listdir()

The same folder is being used by another program. I don't know if that is affecting this behavior. Still, I don't want the desktop.ini file in the second program. How can I achieve this?

Output: enter image description here


Solution

  • import os
    lst = list(set(os.listdir()) - {'desktop.ini', 'whatever.ini'})