I have a folder within my Python project folder that contains around 400 images. I'd like to be able to write a Python script that can access the folder and then pull all of the filenames and print them to the console.
I have the below code, but when I run it I get the error message FileNotFoundError: [WinError 2] The system cannot find the file specified: '/images/'
What do I need to do to fix this? The folder name and os.chdir()
parameters are correct.
import glob, os
os.chdir("/images/")
for file in glob.glob("*.png"):
print(file)
You shouldn't have the leading slash. That indicates you want a directory images
in the root directory. Change "/images/"
to "images/"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.