When a cheap surveillance camera was introduced, if there was a change in the screen, motion detection would work and the image was set to be uploaded to an arbitrary FTP server. The threshold value of motion detection is sensitive to good feeling, and I shoot and upload it with the movement of the sun and a slight shock. Since the upload destination is an arbitrary path, tens of thousands of files will be stored in the same hierarchy.
I'd be happy if it would be distributed to folders of about a year and months, so I decided to create a script that just digs the folder and moves it, referring to the file name.
python
#!/usr/bin/env python
#coding:utf-8
import os
import shutil
JPG_FILE_LIST = []
TGT_FILE_TYPE = '*.jpg'
#List JPG files
#Get only the file name with a specific extension
def get_filename_only_ext(ext_str="*.jpg "):
import glob
global JPG_FILE_LIST
file_list = glob.glob(ext_str)
JPG_FILE_LIST = file_list
#for file in file_list:
# print(file)
get_filename_only_ext( TGT_FILE_TYPE )
print JPG_FILE_LIST
def main():
#Extract the file name line by line
for cur_file in JPG_FILE_LIST:
print cur_file
##Generate destination folder name from file name
# sample_file_name : IPC_IPCamera_14_1_23_22_55_38.jpg
fn = cur_file.split("_")
dist_folder = "20" + fn[2] + "-" + "%02d"%int(fn[3])
##Check the existence of the destination folder
## #Create a folder if it does not exist
if False == os.path.exists( dist_folder ):
os.mkdir( dist_folder )
print "make dir: ", dist_folder
##Move to the destination folder
else:
shutil.move(cur_file, os.path.join( dist_folder, cur_file))
print "move : ", cur_file
if __name__ == '__main__':
main()
print 'done'
If you want to move it with sakura's Rensaba I can't import various things and I can't move orz
Recommended Posts