Very new to Python so please bear with me. I would like to move only the contents of a directory if it exist. Otherwise, would like to move the entire directory. Cleaning up the input directory would be ideal too. Here is what I have so far, for some reason this isn't working:
#!/usr/bin/python
import sys, os, glob, shutil
in_dir = '/images_in/'
out_dir = '/images_out/'
new_dirs = os.listdir(in_dir)
old_dirs = os.listdir(out_dir)
#See if directory already exists. If it doesnt exists, move entire
directory. If it does exists, move only new images.
for dir in new_dirs:
if dir not in old_dirs:
shutil.move(dir, out_dir)
else:
new_images = glob.glob(in_dir + dir + '*.jpg')
for i in new_images:
shutil.move(i, out_dir + dir + i)