import os

dropboxFiles = []
localFiles = []
for dirpath, dirnames, filenames in os.walk(
        '/media/itto/TOSHIBA EXT/Photos/Dropbox/ITTO/Southeast Asia 2017'):
    dropboxFiles += filenames

for dirpath, dirnames, filenames in os.walk(
        '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'):
    if ('Process' not in dirpath):
        localFiles += filenames

localNotInDropbox = []
for file in localFiles:
    if file not in dropboxFiles:
        localNotInDropbox.append(file)
print('************')
for file in dropboxFiles:
    if file not in localFiles:
        print(file)

print(len(localNotInDropbox))
import os
from shutil import copyfile

FOLDER_A = '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'
FOLDER_B = '/media/itto/disk/PRIVATE/AVCHD/BDMV/STREAM'
files_a = []
files_b = []
for dirpath, dirnames, filenames in os.walk(FOLDER_A):
    files_a += filenames

for dirpath, dirnames, filenames in os.walk(FOLDER_B):
    files_b += filenames

inA_notB = []
inB_notA = []
for file in files_b:
    if file not in files_a:
        inB_notA.append(file)
for file in files_a:
    if file not in files_b:
        inA_notB.append(file)

print('{} in Folder A. {} in Folder B.'.format(len(files_a), len(files_b)))
print('In A but not B: {}'.format(len(inA_notB)))
print('In B but not A: {}'.format(len(inB_notA)))


def EnsureFolder(path):
    if os.path.isdir(path):
        pass
    else:
        # Make folder
        os.mkdir(path)


def CopyLeftoverFromBToA():
    for file in inB_notA:
        EnsureFolder(os.path.join(FOLDER_A, 'transfer'))
        src = os.path.join(FOLDER_B, file)
        dst = os.path.join(FOLDER_A, 'transfer', file)
        if not os.path.exists(dst):
            print('Copying {}'.format(file))
            copyfile(src, dst)
        else:
            print('{} previously copied'.format(file))
Add functionality to copy any missing files to the other folder
Add functionality to copy any missing files to the other folder


  import os
+ from shutil import copyfile
  
- dropboxFiles = []
- localFiles = []
+ FOLDER_A = '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'
+ FOLDER_B = '/media/itto/disk/PRIVATE/AVCHD/BDMV/STREAM'
+ files_a = []
+ files_b = []
- for dirpath, dirnames, filenames in os.walk(
+ for dirpath, dirnames, filenames in os.walk(FOLDER_A):
-         '/media/itto/TOSHIBA EXT/Photos/Dropbox/ITTO/Southeast Asia 2017'):
-     dropboxFiles += filenames
+     files_a += filenames
  
- for dirpath, dirnames, filenames in os.walk(
+ for dirpath, dirnames, filenames in os.walk(FOLDER_B):
-         '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'):
-     if ('Process' not in dirpath):
-         localFiles += filenames
+     files_b += filenames
  
- localNotInDropbox = []
+ inA_notB = []
+ inB_notA = []
- for file in localFiles:
+ for file in files_b:
-     if file not in dropboxFiles:
-         localNotInDropbox.append(file)
- print('************')
- for file in dropboxFiles:
-     if file not in localFiles:
+     if file not in files_a:
-         print(file)
+         inB_notA.append(file)
+ for file in files_a:
+     if file not in files_b:
+         inA_notB.append(file)
  
- print(len(localNotInDropbox))
+ print('{} in Folder A. {} in Folder B.'.format(len(files_a), len(files_b)))
+ print('In A but not B: {}'.format(len(inA_notB)))
+ print('In B but not A: {}'.format(len(inB_notA)))
+ 
+ 
+ def EnsureFolder(path):
+     if os.path.isdir(path):
+         pass
+     else:
+         # Make folder
+         os.mkdir(path)
+ 
+ 
+ def CopyLeftoverFromBToA():
+     for file in inB_notA:
+         EnsureFolder(os.path.join(FOLDER_A, 'transfer'))
+         src = os.path.join(FOLDER_B, file)
+         dst = os.path.join(FOLDER_A, 'transfer', file)
+         if not os.path.exists(dst):
+             print('Copying {}'.format(file))
+             copyfile(src, dst)
+         else:
+             print('{} previously copied'.format(file))
Add functionality to copy any missing files to the other folder
## Code Before:
import os

dropboxFiles = []
localFiles = []
for dirpath, dirnames, filenames in os.walk(
        '/media/itto/TOSHIBA EXT/Photos/Dropbox/ITTO/Southeast Asia 2017'):
    dropboxFiles += filenames

for dirpath, dirnames, filenames in os.walk(
        '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'):
    if ('Process' not in dirpath):
        localFiles += filenames

localNotInDropbox = []
for file in localFiles:
    if file not in dropboxFiles:
        localNotInDropbox.append(file)
print('************')
for file in dropboxFiles:
    if file not in localFiles:
        print(file)

print(len(localNotInDropbox))
## Instruction:
Add functionality to copy any missing files to the other folder
## Code After:
import os
from shutil import copyfile

FOLDER_A = '/media/itto/TOSHIBA EXT/Photos/Southeast Asia'
FOLDER_B = '/media/itto/disk/PRIVATE/AVCHD/BDMV/STREAM'
files_a = []
files_b = []
for dirpath, dirnames, filenames in os.walk(FOLDER_A):
    files_a += filenames

for dirpath, dirnames, filenames in os.walk(FOLDER_B):
    files_b += filenames

inA_notB = []
inB_notA = []
for file in files_b:
    if file not in files_a:
        inB_notA.append(file)
for file in files_a:
    if file not in files_b:
        inA_notB.append(file)

print('{} in Folder A. {} in Folder B.'.format(len(files_a), len(files_b)))
print('In A but not B: {}'.format(len(inA_notB)))
print('In B but not A: {}'.format(len(inB_notA)))


def EnsureFolder(path):
    if os.path.isdir(path):
        pass
    else:
        # Make folder
        os.mkdir(path)


def CopyLeftoverFromBToA():
    for file in inB_notA:
        EnsureFolder(os.path.join(FOLDER_A, 'transfer'))
        src = os.path.join(FOLDER_B, file)
        dst = os.path.join(FOLDER_A, 'transfer', file)
        if not os.path.exists(dst):
            print('Copying {}'.format(file))
            copyfile(src, dst)
        else:
            print('{} previously copied'.format(file))