Need to copy files to existing directory and remove files already there with the same name but different extension

William Everett

EDIT: Total rewrite of question for clarity.

I have a directory tree (new) with a bunch of files of with an extension of .new. I have an identical tree (old) where many of the files have names identical to those in the new tree except that the extension is .old. I would like to copy all of the .new files from the new directory tree into the old directory tree which contains the .old files. As a file with a .new extension is written into the old directory tree, I would like to delete any file with the same name but a .old extension.

So, if in the new directory tree, there is a file named new/foo/bar/file.new, it will be copied to the old directory tree as old/foo/bar/file.new and then the file old/foo/bar/file.old will be deleted if it exits.

EDIT #1

This answer was hashed out below (using the old question that had extraneous background information that was confusing). See the actual solution that I worked out below as one of the answers.

William Everett

This was the final answer that got hashed out in the comments for terdons answer.

cd new
for i in */*/*.new; do cp "$i" "path/to/old/${i}" && rm "path/to/old/${i//new/old}"; done

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Copy files of same name into same directory

From Dev

How can I copy multiple files in the same directory with different names but same extension in bash?

From Dev

Copy files to same directory with another name

From Dev

Renaming Files With Same Name, Different Extension in Linux:

From Dev

Delete files same name but different file extension

From Dev

Python copy files to a new directory and rename if file name already exists

From Dev

Copy files to a destination folder only if the files already exist. but the source files have a different file extension

From Dev

Ability to add files to a directory but not remove existing files

From Dev

Recursively copy (and rename) files to their own same directory with another name

From Dev

Recursively copy (and rename) files to their own same directory with another name

From Dev

Copy a list of files with the same names but different extensions to a new directory

From Dev

Move a files that have the same name but different extension. Powershell

From Dev

for loop calling two different files (same name, different extension) across several files

From Dev

Use gzip to compress the files in a directory except for already existing .gz files

From Dev

How to copy multiple files with a same name from children directory to another directory without losing the parent directory?

From Dev

Linux : Copy Multiple files and remove it's extension

From Dev

Remove a specific extension from all the files in a directory

From Dev

How do I copy same files with a particular extension to another directory in terminal

From Dev

How Can Vim and Windows See Two Different Files that Have the Same Name in the Program Files Directory

From Dev

Copy files to directory with random name with batch

From Dev

How to copy all files in same directory as gulpfile?

From Dev

How to copy all files in same directory as gulpfile?

From Dev

Copy *changed/new files only* to a DIFFERENT directory?

From Dev

rsync: copy updated/new files to DIFFERENT directory

From Dev

Copy all files with certain extension to another directory, while changing the extension

From Dev

Rename all files with the same extension and any name

From Dev

How do I copy variously named files with the same extension to all have a standard file name?

From Dev

How to merge files in git when directory is already moved to different directory

From Dev

Grunt-Contrib-Copy, how to copy contents of a directory keeping the same folder structure without overwriting existing files/folders in dest folder?

Related Related

  1. 1

    Copy files of same name into same directory

  2. 2

    How can I copy multiple files in the same directory with different names but same extension in bash?

  3. 3

    Copy files to same directory with another name

  4. 4

    Renaming Files With Same Name, Different Extension in Linux:

  5. 5

    Delete files same name but different file extension

  6. 6

    Python copy files to a new directory and rename if file name already exists

  7. 7

    Copy files to a destination folder only if the files already exist. but the source files have a different file extension

  8. 8

    Ability to add files to a directory but not remove existing files

  9. 9

    Recursively copy (and rename) files to their own same directory with another name

  10. 10

    Recursively copy (and rename) files to their own same directory with another name

  11. 11

    Copy a list of files with the same names but different extensions to a new directory

  12. 12

    Move a files that have the same name but different extension. Powershell

  13. 13

    for loop calling two different files (same name, different extension) across several files

  14. 14

    Use gzip to compress the files in a directory except for already existing .gz files

  15. 15

    How to copy multiple files with a same name from children directory to another directory without losing the parent directory?

  16. 16

    Linux : Copy Multiple files and remove it's extension

  17. 17

    Remove a specific extension from all the files in a directory

  18. 18

    How do I copy same files with a particular extension to another directory in terminal

  19. 19

    How Can Vim and Windows See Two Different Files that Have the Same Name in the Program Files Directory

  20. 20

    Copy files to directory with random name with batch

  21. 21

    How to copy all files in same directory as gulpfile?

  22. 22

    How to copy all files in same directory as gulpfile?

  23. 23

    Copy *changed/new files only* to a DIFFERENT directory?

  24. 24

    rsync: copy updated/new files to DIFFERENT directory

  25. 25

    Copy all files with certain extension to another directory, while changing the extension

  26. 26

    Rename all files with the same extension and any name

  27. 27

    How do I copy variously named files with the same extension to all have a standard file name?

  28. 28

    How to merge files in git when directory is already moved to different directory

  29. 29

    Grunt-Contrib-Copy, how to copy contents of a directory keeping the same folder structure without overwriting existing files/folders in dest folder?

HotTag

Archive