I'm trying to copy certain .JPG files from my photocard to another directory. The files are named IMG_7853.JPG, IMG_7854.JPG, and so on (they range from IMG_0001.JPG to IMG_9999.JPG). If I want to copy all files greater than IMG_7853 what's the best approach in python. The code below works fine for listing all files in the directory, but I wasn't sure how to go about making the comparison based on the partial filename.
#! /bin/python
import re
import os
def copyphoto():
path="/media/CANON_DC/DCIM"
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith(".JPG"):
print name