TLDR: I have images in folders and I want to use python to add all images to a ppt slide but it gives No file or Directory error found error even though the name is exactly the same.
First I download them into the dataset folder
#downloading the images
from bing_image_downloader import downloader
df = pd.read_csv('multi-modal_market_map.csv')
for i in range(len(df)):
co = df.iloc[i,0]
downloader.download(co, limit=1, output_dir='dataset', adult_filter_off=True, force_replace=False, timeout=60, verbose=True, filter ="transparent")
It makes a folder for each company and puts an image under parent directory “dataset”. So each image is for example dataset/1mind/Image_1.png
Then I’m trying to loop over the dataset folder to get into each sub folder and get the image to add to the slide.
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_slide_layout)
for i in os.listdir("dataset"):
if i == ".DS_Store":
print("Not applicable")
else:
base = "/dataset/"+i+"/Image_1.png"
print(base)
left = top = Inches(1)
pic = slide.shapes.add_picture(base, left, top)
prs.save('test.pptx')
It keeps giving me the error below, even though that is the file path. I’ve checked the current working directory in the loop and it’s in the parent directory of dataset. Any ideas?
FileNotFoundError: [Errno 2] No such file or directory: '/dataset/Gamma/Image_1.png'