I have a source directory with sub directories with files. I also have a destination directory with sub directories with another structure.
fileNames = <get all file names from source directory>
for fileName in fileNames {
if <not found in destination directory> {
print fileName
}
}
How can I do pseudo code above?
EDIT:
Example file structure:
./sourcedir/file1.txt
./sourcedir/foldera/file2.txt
./sourcedir/foldera/missingfile.txt
./destdir/file2.txt
./destdir/folderb/file1.txt
So missingfile.txt should be printed. But not file1.txt or file2.txt since they can be found under destdir somewhere.
EDIT2: I managed to do a Python implementation this was what was aiming for. I had some trouble with the bash answers when trying them. Can it be done simpler in bash?
import os
import fnmatch
sourceDir = "./sourcedir"
destinationDir = "./destdir"
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
print sourceDir
for sourcefilename in find_files(sourceDir, '*'):
#if not sourcefilename.lower().endswith(('.jpg', '.jpeg', '.gif', '.png','.txt','.mov','3gp','mp4','bmp')):
# continue
shouldPrint = True
for destfilename in find_files(destinationDir, '*'):
sourceBaseName = os.path.basename(sourcefilename)
destBaseName = os.path.basename(destfilename)
if sourceBaseName == destBaseName:
shouldPrint = False
break
if shouldPrint:
print 'Missing file:', sourcefilename