In Python, I only want to list all the files in the current directory ONLY. I do not want files listed from any subdirectory or parent.
There do seem to be similar solutions out there, but they don't seem to work for me. Here's my code snippet:
for subdir, dirs, files in os.walk('./'):
for file in files:
do some stuff
files = [f for f in os.listdir('.') if os.path.isfile(f)] for f in files: # do something
But be careful while applying this to other directory, like
files = [f for f in os.listdir(somedir) if os.path.isfile(f)].
which would not work because
f is not a full path but relative to the current dir.
Therefore, for filtering on another directory, do
(Thanks Causality for the hint)