Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Lets say we have two directories:

Directory A:

aaa.mov
bbb.mov
ccc.mov
ddd.mov
eee.mov

Directory B:

subdir1/aaa.mov
subdir1/bbb.mov
subdir2/subsubdir/ccc.mov

How could I transfer from A to B/newDir, all files which do not exist under any B's subdirectories (ddd.mov & eee.mov)?

share|improve this question
    
Judging from /, operating system is Linux or Mac OS X? –  Olli Feb 27 '11 at 10:02
    
well..Mac OS X :) –  nuc Feb 27 '11 at 10:04
add comment

1 Answer

up vote 3 down vote accepted

A simple shell script will achieve what you want...

#!/bin/sh

SRCDIR=dira
DSTDIR=dirb
SRCFILES=`find ${SRCDIR} -type f -exec basename '{}' \;`
mkdir -p ${DSTDIR}/NewDir

for FILE in ${SRCFILES}
do
        FOUND=`find ${DSTDIR} -name ${FILE} -type f`
        if [ -z ${FOUND} ]
        then
                echo -n "Copying ${FILE}..."
                cp ${SRCDIR}/${FILE} ${DSTDIR}/NewDir
                echo "done"
        fi
done
share|improve this answer
    
Thank you so much! It worked so great! :) –  nuc Feb 27 '11 at 13:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.