3 Added example of files and folders
source | link

I am not sure how to approach on moving files based on their name into their respective directories. Basically, I have a bunch of tv shows that start like tvshowname.season.episode.ext or tv.show.name.season.episode.ext. I have directories named Show Name, Show Name1, Show Name2, etc. I would like to copy the files based on their name into the directories with the same name.

Current Files

Game of Thrones
Shooter
The Curse of Oak Island  
Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA.mkv
Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA.mp4
Real Vikings
Van Helsing

So far I have made this

    #!/bin/bash
for FILE in "`ls *.{mp4,mkv}`"
do
        filename=$(basename "$FILE")
        extension=${filename##*.}
        filename=${filename%.*}
echo $filename
done

The issue that I am running into now, is how to get the first few words or at least the name of the show from the file name itself. Then move it into the directory based on that name. Each directory is listed as The Flash, The Curse of Oak Island, etc.

I am not sure how to approach on moving files based on their name into their respective directories. Basically, I have a bunch of tv shows that start like tvshowname.season.episode.ext or tv.show.name.season.episode.ext. I have directories named Show Name, Show Name1, Show Name2, etc. I would like to copy the files based on their name into the directories with the same name.

So far I have made this

    #!/bin/bash
for FILE in "`ls *.{mp4,mkv}`"
do
        filename=$(basename "$FILE")
        extension=${filename##*.}
        filename=${filename%.*}
echo $filename
done

The issue that I am running into now, is how to get the first few words or at least the name of the show from the file name itself. Then move it into the directory based on that name. Each directory is listed as The Flash, The Curse of Oak Island, etc.

I am not sure how to approach on moving files based on their name into their respective directories. Basically, I have a bunch of tv shows that start like tvshowname.season.episode.ext or tv.show.name.season.episode.ext. I have directories named Show Name, Show Name1, Show Name2, etc. I would like to copy the files based on their name into the directories with the same name.

Current Files

Game of Thrones
Shooter
The Curse of Oak Island  
Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA.mkv
Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA.mp4
Real Vikings
Van Helsing

So far I have made this

    #!/bin/bash
for FILE in "`ls *.{mp4,mkv}`"
do
        filename=$(basename "$FILE")
        extension=${filename##*.}
        filename=${filename%.*}
echo $filename
done

The issue that I am running into now, is how to get the first few words or at least the name of the show from the file name itself. Then move it into the directory based on that name. Each directory is listed as The Flash, The Curse of Oak Island, etc.

2 edited tags
| link
1
source | link

Moving files into directory based on their name

I am not sure how to approach on moving files based on their name into their respective directories. Basically, I have a bunch of tv shows that start like tvshowname.season.episode.ext or tv.show.name.season.episode.ext. I have directories named Show Name, Show Name1, Show Name2, etc. I would like to copy the files based on their name into the directories with the same name.

So far I have made this

    #!/bin/bash
for FILE in "`ls *.{mp4,mkv}`"
do
        filename=$(basename "$FILE")
        extension=${filename##*.}
        filename=${filename%.*}
echo $filename
done

The issue that I am running into now, is how to get the first few words or at least the name of the show from the file name itself. Then move it into the directory based on that name. Each directory is listed as The Flash, The Curse of Oak Island, etc.