saqib1066 Wrote:FileNotFoundError: [Errno 2] No such file or directory:I have never seen Python lie about this,so what reported is the problem..
To show a test with the part that give error.
First test:
import os directory = r'C:/code/img/' # See that i use / other way for file in os.listdir(directory): print(file)
Output:foo.html
img.py
test.png
WeatherIconsclear-day.png
Works see that files are there.Add second part and
print()
work fine as debug tool,can also add repr
.import os directory = r'C:/code/img/' # See that i use / other way for file in os.listdir(directory): #print(file) if file.endswith('.jpeg') or file.endswith('.png'): # expand depending on what file types your icons are original_path = directory + file # open images so they can be resized print(repr(original_path)) # Use print to see that path is correct,repr show all fp = open(original_path)
Output:'C:/code/img/test.png'
'C:/code/img/WeatherIconsclear-day.png'
No error so the files get open bye open()
.The part that easy can go wrong is
original_path = directory + file
like missing a /
or \\
(never single \
in path) in the concatenate.