0

I need to copy file names from one folder to another. File contents are never changed. No files are overwritten, moved or copied. It's only about file names.

I have a folder A with files named:

  • Show - S01E01 - Descriptive title.mkv
  • Show - S01E02 - Another descriptive title?.mkv
  • Show - S01E03 - Another complex name!.mkv
  • ...

I have a folder B with files named:

  • show.s01e01.mkv
  • show.s01e02.mkv
  • show.s01e03.mkv
  • ...

I don't need the files in folder A anymore because the files in folder B have a better quality. But I don't want to manually rename all files in folder B to have the proper file name including the episode title. I would like to automatically transfer the proper file names from the files in folder A to the files in folder B. The alphabetical order is identical in both folders. So the nth file in folder B corresponds to the nth file in folder A. In the end folder B would contain exactly the same file names as in folder A but the files contents are different of course.

Example:

Before:

Folder A:

  • Show - S01E01 - Green Apples.mkv
  • Show - S01E02 - Peaches in the Sky.mkv

Folder B:

  • show.s01e01.mkv
  • show.s01e02.mkv

After:

Folder A:

  • Show - S01E01 - Green Apples.mkv
  • Show - S01E02 - Peaches in the Sky.mkv

Folder B:

  • Show - S01E01 - Green Apples.mkv
  • Show - S01E02 - Peaches in the Sky.mkv

How do i do this in Bash? (Or any other GNU/Linux tool, KDE OK too)

  • Do you mean copy the ones that don't yet exist in the other folder? – Paul Oct 21 '13 at 23:11
  • Both file sets exist already. The new ones have a better quality for example. I don't want to rename them manually and add every episode title but take the names from the old version and use them for the new version. – problemofficer Oct 21 '13 at 23:14
  • Its a little bit hard to understand try adding an example of your desired output. – meda Oct 21 '13 at 23:30
  • I added an example. – problemofficer Oct 22 '13 at 0:02
0

To do what you want would take some scripting. Not too involved, but it is re-inventing the wheel a bit.

What I would suggest is installing tvnamer https://github.com/dbr/tvnamer

This will use a database to consistently rename all of your media. If you run this across everything then both the low and high quality shows will have the same name, so you can just copy over the high quality ones over the low quality ones with cp.

| improve this answer | |
0

You can try bash arrays. I am giving a skeletal solution below.

cd $DIR1
list1=( * )

cd $DIR2
i=0
for f in *
do
  mv $f ${list1[$i]}
  (( i += 1 ))
done

As you have mentioned in the question the assumption is that exact number of files are in both directories and alphabetically they are in order. More error checking and may be pattern matching can be done to make it robust.

list1 is an array with the filenames in that directory. ${list1[0]} is the first element in the array, etc. I am not sure if this will work with filenames with whitespaces, etc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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