Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Command to move all mkv files up a folder

Featured Replies

Hi there,

Just finished converting my 1000+ old dvds to mkvs with makemkv, it placed each file in the VIDEO_TS folder.

I would like to find a command that 

- moves up each mkv to the parent folder

Once that is done I want to backup the VIDEO_TS folders to a backup folder retaining the parent folder name.

Basically I want to separate the two, so I can add to emby the folders containing the MKV files.

Each parent folder also contains the xml file which emby uses to identify the movie, I'd like to keep that too.

Thank you guys for your help in advance!

 

Here is a script that should do what you need.  Set "movies" and "backup" to your folders.

move_movies.sh

#!/bin/bash

movies="/mnt/user/test/movies"
backup="/mnt/user/test/backup"

process()
{
    local movieDir=$1
    local backupDir=$2
    
    pushd "$movieDir" >/dev/null
        find ./ -iname "*.mkv" -exec mv -f {} . \;
        mkdir -p "$backupDir"
        mv -f AUDIO_TS VIDEO_TS "$backupDir"
    popd >/dev/null
}

ls -1d "$movies"/*/ | sed 's/\/*$//' |\
while read movie
do
    name="$(sed 's/.*\///g' <<< $movie)"
    back="$backup/$name"

    printf "$name\n"

    if [ -d "$movie/DVD1" ]
    then
        ls -1d "$movie"/DVD*/ | sed 's/\/*$//' |\
        while read dvd
        do
            num="$(sed 's/.*\///g' <<< $dvd)"
            process "$dvd" "$back/$num"
        done
    else
        process "$movie" "$back"
    fi
done

 

Edited by JoeUnraidUser

  • Author

Thank you Joe! I checked one more time and it is slightly more complex than what I stated.

The program created an additional folder in each VIDEO_TS file, which adds underscores if the folder name has multiple words in it. Examples:

\\tower\unraid\dvds\forrest gump\VIDEO_TS\FORREST_GUMP

\\tower\unraid\dvds\everything you wanted to ask about sex\VIDEO_TS\EVERYTHING_YOU_WANTED_TO_ASK_ABOUT_SEX

 

On 9/22/2019 at 6:51 PM, gnollo said:

Thank you Joe! I checked one more time and it is slightly more complex than what I stated.

The program created an additional folder in each VIDEO_TS file, which adds underscores if the folder name has multiple words in it. Examples:

\\tower\unraid\dvds\forrest gump\VIDEO_TS\FORREST_GUMP

\\tower\unraid\dvds\everything you wanted to ask about sex\VIDEO_TS\EVERYTHING_YOU_WANTED_TO_ASK_ABOUT_SEX

I modified the script to move "mkv" files from anywhere under the movie folder.

Edited by JoeUnraidUser

  • Author

I've never run a script on unraid before, how do I do that (I mostly still a windows guy)?

23 hours ago, gnollo said:

I've never run a script on unraid before, how do I do that (I mostly still a windows guy)?

  1. Install the "CA User Scripts" app.
  2. Go to the settings tab and click on the "User Scripts" icon.
  3. Click on "ADD NEW SCRIPT".
  4. Give the script a name.
  5. Click on the name of the script.
  6. Select "Edit Script".
  7. Paste your script and make any changes.
  8. Hit "SAVE CHANGES".
  9. To the right of the name click "RUN SCRIPT".

 

Edit:  I would test it first on a couple movies.  For example:

test
├── backup
└── movies
    ├── everything you wanted to ask about sex
    └── forrest gump

 

Edited by JoeUnraidUser

  • Author

Ok, thank you again Joe, I am all set. How do I know that the script will not affect any other folder (containing another 3500 movies) than the one where all the DVDs are set? I moved them to a different location and left a few behind in the DVD folder, to perform a test run.

52 minutes ago, gnollo said:

Ok, thank you again Joe, I am all set. How do I know that the script will not affect any other folder (containing another 3500 movies) than the one where all the DVDs are set? I moved them to a different location and left a few behind in the DVD folder, to perform a test run.

It will only affect the folders under the folders you define with the variables "movies" and "backup"

Edited by JoeUnraidUser

  • Author

So if I create these folders

\\tower\test

\\tower\test\movies

\\tower\test\backup

drop some test dvds in the movies folder, I can run the script to test it?

On 9/23/2019 at 6:57 PM, gnollo said:

So if I create these folders

\\tower\test

\\tower\test\movies

\\tower\test\backup

drop some test dvds in the movies folder, I can run the script to test it?

Yes.

 

Note:

1. On Linux, slash / is used for folders instead of the Windows backslash \

2. On Unraid, the share \\tower\test is represented on Linux as /mnt/user/test

3. Linux folder names are case sensitive.

 

So your folder names in Linux should look like this:

movies="/mnt/user/test/movies"
backup="/mnt/user/test/backup"

 

Edited by JoeUnraidUser

  • Author

Ok, this is the message that appeared during the run.

 

Script location: /tmp/user.scripts/tmpScripts/mkv dvd fixer/script
Note that closing this window will abort the execution of this script
CATCH_AND_RELEASE
Cary Grant, A Class Apart
casino royale
casino
casshern
castaway
catch me if you can
mv: cannot stat 'VIDEO_TS': No such file or directory

That looks good except it didn't see a VIDEO_TS folder under "catch me if you can".

Was there a folder VIDEO_TS folder under "catch me if you can"?

 

Otherwise how did all the other movies work out?

  • Author

Worked perfectly. One of the folders didn't have a VIDEO_TS folder, which is why it gave the error message. One last thing would be to also move across the AUDIO_TS folder? You are an absolute gem Joe this is going to save me a ton of time! And if anything goes wrong I can always fix it quickly as I have the original files in the backup folder! This is ace!

4 minutes ago, gnollo said:

Worked perfectly. One of the folders didn't have a VIDEO_TS folder, which is why it gave the error message. One last thing would be to also move across the AUDIO_TS folder? You are an absolute gem Joe this is going to save me a ton of time! And if anything goes wrong I can always fix it quickly as I have the original files in the backup folder! This is ace!

I changed the script so it also moves AUDIO_TS to the backup.

  • Author

run it on the same folders

 

Script location: /tmp/user.scripts/tmpScripts/mkv dvd fixer/script
Note that closing this window will abort the execution of this script
ls: cannot access '/mnt/user/test/movies/*/': No such file or directory

1 minute ago, gnollo said:

run it on the same folders

 

Script location: /tmp/user.scripts/tmpScripts/mkv dvd fixer/script
Note that closing this window will abort the execution of this script
ls: cannot access '/mnt/user/test/movies/*/': No such file or directory

Are your movies in \\tower\test\movies all lowercase?

  • Author

Also noticed that in one of the folders I had two subfolders (DVD1 and DVD2). The script seems to have copied the two mkv files over each other so I only have one mkv file in that specific movie folder. No biggie, is there is a way to identify which folders have subfolders once the merge is done and I can rectify that manually by recreating the missing mkv.

  • Author

test lowercase

Backup and Movies are Capital

4 minutes ago, gnollo said:

test lowercase

Backup and Movies are Capital

I changed the folders to be all lowercase to match up with

\\tower\test\movies

\\tower\test\backup

Can you change the folders to lowercase or should I change the script back?

Edited by JoeUnraidUser

  • Author
I can change the script to accommodate for DVD# subfolders.  It will take another day to make the changes.  What is the structure under the DVD# folders.  For example, does it have a VIDEO_TS and AUDIO_TS under DVD1?
No need, it will only be a handful, I'll do a search for dvd in the folders adds identify which have subfolders, and fix those first manually moving the mkv files.

Sent from my SM-A520F using Tapatalk

  • Author
I changed the folders to be all lowercase to match up with
\\tower\test\movies
\\tower\test\backup
Can you change the folders to lowercase or should I change the script back?
I'll change the folders to lowercase when I'm back from work and test

Sent from my SM-A520F using Tapatalk

Too late.  I already changed the script to accommodate for DVD# subfolders.  It assumes the structure under each DVD# folder contains VIDEO_TS and AUDIO_TS.

Edited by JoeUnraidUser

  • Author
Too late.  I already changed the script to accommodate for DVD# subfolders.  It assumes the structure under each DVD# folder contains VIDEO_TS and AUDIO_TS.
Fab. I'll test that too!

Sent from my SM-A520F using Tapatalk

  • Author

Run it on the folder, went through all a to z and completed

some of the error messages

mv: cannot stat 'AUDIO_TS': No such file or directory

rev: stdin: Invalid or incomplete multibyte or wide character

mv: cannot move 'VIDEO_TS' to '/mnt/user/unraid/dvdbackup/VIDEO_TS': Directory not empty

mv: './Charlie And The Chocolate Factory-1.mkv' and './Charlie And The Chocolate Factory-1.mkv' are the same file

mv: cannot stat 'VIDEO_TS': No such file or directory

I will investigate them one by one tomorrow

  • Author

mv: './Charlie And The Chocolate Factory-1.mkv' and './Charlie And The Chocolate Factory-1.mkv' are the same file

I think this happened when the mkv was already in the root of the movie folder as I already manually moved it there (and removed the video ts folder)

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.