File not found with os.listdir(dir)
- listdir
- path
Confusingly, os.listdir(dir)
returns a list of file names relative to dir
; if this is not your current working directory (i.e. .
) you cannot directly open, copy, or otherwise manipulate the files that it returns. You have to resolve the relative file name with something like
for filename in os.listdir(dir):
with open(os.path.join(dir, filename)) as filehandle:
...