osx - Find and Replace Image Files Between Two Folders -
i have 2 folders on mac's hard drive.
directory a, , directory b
both directories contain image files.
i need find matching filenames dir a.
if find match overwrite file in dir matching 1 dir b.
how should approach this?
rsync the best tool synchronizing files. has tons of options sure read man page in detail.
rsync -rv --inplace --existing /path/to/dir/b/* /path/to/dir/a if want write script should looking for:
#!/bin/bash dir_a='/path/to/dir_a' dir_b='/path/to/dir_b' file in "$dir_b"/*; name="${file##*/}" if [[ -e $dir_a/$name ]]; echo "match found = $name"; cp "$file" "$dir_a" fi done what is, files in directory b , extracts file name (since use absolute paths). checks filename see if exists in directory a. -e test that. if successful test print message saying match found along filename. proceed copy file directory b directory a.
now may choose remove message prints out screen , use mv instead of cp if don't want copy present in directory b.
Comments
Post a Comment