Skip to content

Instantly share code, notes, and snippets.

@tomasinouk
Created June 23, 2016 06:17
Show Gist options
  • Save tomasinouk/520c56628615fc6685af2cb6faca6070 to your computer and use it in GitHub Desktop.
Save tomasinouk/520c56628615fc6685af2cb6faca6070 to your computer and use it in GitHub Desktop.
recursively search for files in directories and copy them to new location with modified name
import shutil
import os
import re
source = os.walk("~/Downloads/camera/")
destination = "~/Downloads/mobotix-pic/"
# for files in source:
for root, dirs, files in source:
# print(files)
for _file in files:
if _file.endswith(".jpg"):
print("Found this file: " + root + "/" + _file)
# print ("root: " + root)
# print("dirs: " + dirs)
prefix = "MT644"
name_arr = re.split('\_', _file)
shutil.copy(root + "/" + _file, destination + prefix + "_" + name_arr[0] + "_" + name_arr[1] + "-" + name_arr[2] + ".jpg")
# prefix = "MT644"
# name_arr = re.split('\_','2016-06-16_14_30_01.291.jpg')
# print name_arr
# date_arr = re.split('\-', name_arr[0])
# print("Year: " + date_arr[0])
# print("Month: " + date_arr[1])
# print("Day: " + date_arr[2])
# print("Date: " + name_arr[0])
# print("Hour: " + name_arr[1])
# print("Minute: " + name_arr[2])
# print ("Option 1 - Name: " + prefix + "_" + name_arr[0] + "_" + name_arr[1] + "-" + name_arr[2] + ".jpg")
# print ("Option 2 - Name: " + prefix + "_" + date_arr[2] + "-" + date_arr[1] + "-" + date_arr[0] + "_" + name_arr[1] + "-" + name_arr[2] + ".jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment