Can't write the image to the directory sensor.snapshot().save ()

Can’t write the image to the directory.

sensor.snapshot().save(“dir%03d/I_%03d.jpg” % (freeDirNumber,counterNumber), quality = 90)

freeDirNumber, counterNumber is int in range 0…255. The directory exists.

Throws an error “OSError: Could not find a patch” and I cannot figure out the syntax.
Please help solve the problem!

You need to create the folders first.

I was created!
if not (’%s%d’%(‘dir’,freeDirNumber)) in os.listdir(): os.mkdir(’%s%d’%(‘dir’,freeDirNumber))

print (‘freeDirNumber=’,freeDirNumber)

directory = ‘%03d’ % freeDirNumber

print (‘directory=’,directory)
print (os.listdir())

from terminal:

freeDirNumber= 19

directory= 019

[’.openmv_disk’, ‘System Volume Information’, ‘dir1’, ‘dir2’, ‘dir3’, ‘dir4’, ‘dir5’, ‘dir6’, ‘dir7’, ‘dir8’, ‘dir9’, ‘dir10’, ‘dir11’, ‘dir12’, ‘dir13’, ‘dir14’, ‘dir15’, ‘dir16’, ‘dir17’, ‘dir18’, ‘dir19’]

Yeah, so, your string format code forces leading zeros. Meaning the names don’t match.

Only saving the image does not work. I’ve been reading and experimenting for half a day. does not work out.sensor.snapshot().save(“dir%03d/I_%03d.jpg” % (freeDirNumber,counterNumber), quality = 90)
How to fix???
fileNumber=’%03d’ % counterNumber
print (‘counterNumber=’,counterNumber)
print (‘fileNo=’,fileNumber)
print (‘dir%(freeD)03d/I_%(counterN)03d.jpg’ % {“freeD”: freeDirNumber, “counterN”: counterNumber})

terminal answer all correct:
counterNumber= 1
fileNo= 001

Thanks for the tip! I didn’t understand right away, but then I removed the leading 0. Everything worked! I just started getting acquainted with Python, I used to study Arduino. I must say that the documentation is not very good, there are too few code examples in the documentation!

sensor.snapshot().save(‘dir%d/I_%d.bmp’ % (freeDirNumber, counterNumber))

It’s not a beginner product. You should know how to code python. It’s expected. Additionally, you can Google anything about Python on the internet.

I used to start working right away. Almost without studying anything theoretically. Therefore, it is important for me to have good examples directly in the description of Micro-Python. And they are not! This is a big disadvantage for me! I give that I am not the only one. Arduino has a reference with simple descriptions and examples - a great reference for getting started quickly. Searching for answers on Google is ineffective. There is not much about Micro-Python, it’s not Arduino or C ++! But I am very grateful to you for your help!