I have a folder of 1000 photos that I'd like to make a timelapse of. The photos are shot every 60 seconds, and I'd like to make a 10 minute interval timelapse. So I need to delete every 2nd to 9th photo and have it loop. For example, given 1000 photos in a folder, I'd like the script to keep photo 1, 10, 20, 30 and so on and so forth. At the end of this script, the folder should only contain 100 photos.
The following code removes every "10th" photo, which doesn't do exactly as I want:
import os
dir_to_clean = '/Users/myname/Desktop/TBD'
l = os.listdir(dir_to_clean)
for n in l[::10]:
os.unlink(dir_to_clean + '/' + n)
How do I modify this code so that it deletes every 2nd-9th photo? It should still be able to run if the folder does not have an even number of files (e.g. if it has 1005 files).