Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #noParity=true
- #arrayStarted=true
- ## This script will create folders from files. First it will remove
- ## all spaces and create a folder from the file name
- ## It will also move files/directories to final location if you uncomment down in the code
- ## It will also change your file permissions from root to nobody uncomment below to use
- ## Adjust your directories below for your needs.
- ## Have Questions ask kizer on unraid forum
- ## All code has been cobbled together by me and tested on my own system to insure it works
- ## Source Directory of Files, change below to your path. I left mine in for example
- FROM=/mnt/cache/uploads/Tv-Incoming
- ## Script will leave renamed files where they are unless you comment and adjust below
- ## Keep in mind you have to uncomment below and the 2nd to last line to work
- ## Only if you want to move new folder to another location. Change below to your path
- ## and uncomment near the very bottom of this script
- NEWLOCATION=/mnt/cache/Media/Movies
- ## Remove Spaces-Linux and spaces are no good together
- cd $FROM/
- for f in *\ *; do mv "$f" "${f// /.}"; done
- ## Create Folder from name and move to final location. File types editable below.
- ## If File type is not listed below it will not be moved or renamed
- for FILE in `ls $FROM/ | egrep "mkv|mp4|avi|vob|iso|MKV|MP4|AVI|VOB|ISO"`
- do
- DIR=`echo $FILE | rev | cut -f 2- -d '.' | rev`
- ## Make Directory
- mkdir $FROM/$DIR
- ## Move File into new Directory
- mv $FROM/$FILE $FROM/$DIR
- ######################## OPTIONAL BELOW #################
- ## Remove Pound symbol option you would like to use
- ## Change Permissions so Everything is Happy
- ## Changes from read write from ROOT
- #chmod -R u-x,go-rwx,go+u,ugo+X $FROM
- ## Changes owner from ROOT to Nobody which is pretty standard on unraid
- #chown -R nobody:users $FROM
- ## Move Directory to Final Place. Leave Comment if this is the final place
- #mv $FROM/$DIR $NEWLOCATION
- ###################### DONE OPTIONAL ####################
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement