无法移动目录不为空

uxserx-bw

由于人们想要了解更多而进行编辑,然后我只想知道如何在不同地方处理两个具有相同名称的目录,并且如果文件位于目标区域中,则mv不允许将其移入另一个目录。

他们想知道我想做什么以及为什么这么做...

我的脚本将所有导演都放在父目录中,然后一次遍历每个目录中包含mp3或flac文件的文件,然后检查是否需要通过比特率检查进行重采样,然后检查比特率是否更大然后设置重采样比特率重新采样文件,如果不跳过,则下一步:通过TAG信息重命名所有文件,如果文件本身中没有TAG信息,则将其从目录中删除,然后通过添加艺术家目录和专辑目录或其他方式,但是如果需要,可以将TAG信息添加到文件中,然后使用META TAG信息重命名文件。

歌曲-artist.mp3

使用此脚本,当脚本在该艺术家目录中的所有文件上完成处理后,我将文件保留在原始目录中,然后需要将其移出该分区目录,以便再次运行该脚本时,它不会返回超过所有刚刚完成的文件...

所以我将艺术家目录重命名为艺术家名称,因为其中一些人在目录名称中都写有艺术家/专辑/唱片@ 320MP3废话,因此我将其清理掉,只是将其重命名为META TAG Artsit信息,然后将其移动到另一个父目录,以使所有父目录都在该目录sys中完成。

因为我有许多同一位艺术家的不同专辑目录名称,以及父目录中所有文件夹中不同目录中的重复文件。所有同一个具有不同命名dirs的艺术家-示例-

1爱丽丝·库珀(Alice Cooper)疯子/专辑名称/旧文件

完成后它将是

爱丽丝·库珀/专辑名称/新文件

2爱丽丝·库珀(Alice Cooper),这里有其他专辑/专辑/ CD1 / Old-iles

爱丽丝·库珀(Alice Cooper)不管在这里/专辑/ CD2 /旧文件

完成后将

爱丽丝·库珀/专辑/ CD1 / New-iles

爱丽丝·库珀/专辑/ CD2 /新文件

步骤 :

循环之一是获取dir名称以进行处理

循环二是遍历该dir构造函数中的每个文件并重新映射,如果需要,请重新标记文件,重命名文件,当所有文件完成后,将该dir重命名为艺术家名称,然后将其从该父目录移到另一个父目录中以获取它妨碍了-

该父目录中的下一个目录重复步骤

循环遇到已经重命名的专辑名称匹配项并移动到其他父目录时出现问题,它将引发该错误。

mv -f /from/here/sameNameDir    /to/here/ - that has the same name dir in it already

如果Dir没有移动,那么脚本将循环浏览所有已经完成的文件,因为我有40,000多个文件,这需要花一些时间,因此我将完整的目录移出该目录,以便在第二次运行第二天编写新脚本

我的脚本可以运行,但有一些错误,因此它仍处于测试模式,因此其中包含很多回声:以及我重复使用我编写的代码,因此您也可能会在其中看到电影注释。

#!/bin/bash

# started writting this on 11-24-2015


typeset -i FilesCountInSecondLoop    FilesInDirCount  filesLeftToDo   DirCountDn
let        FilesCountInSecondLoop=0  FilesInDirCount=0 filesLeftToDo=0 DirCountDn=0

typeset -i cycleThroughFilesCount    
let        cycleThroughFilesCount=0  

working_dir="/media/data/test-run"

move_to="/media/data/move_to_test"


# where you keep this script to run it in a terminal
# it is written so that you do not have to put it in the 
# working directory or directories to eliminate having to put
# a separate script in every folder to run it
##############################################

 script_dir="$HOME/working"


# max rate you want your orgianl files to be check for to be 
# resampled at

LameCheckRate=192

# bitrate you want your FLAC files coverted to mp3 in
# you can convert your FLAC to a higher rate then the
# resmapled mp3 if you like 
##################################

flac_convert_brate=192

# this is the FLAC settings it runs at
# flac -cd "$FILENAME" | lame -b "${flac_convert_brate}" - "$newFile" 


# LAME settings VBR low and High end

LameLowEnd=128 
LameHighEnd=192

# this is the LAME settings it runs at
##lame -V2 -b"${LameLowEnd}" -B"${LameHighEnd}" -F --vbr-new -m j -q2

#####################
## DO NOT CHANGE ####
runTime=1 ###########        
convertN=$1 #########
#####################
# gets amount of files wanted to resample on run
# from command line args
function rst(){

if [[ convertN -lt runTime ]]; then
  echo " you forgot to enter an amount to resample"
  ConvertNum=0
  exit 1
  else
  ConvertNum=$((convertN))
  return $ConvertNum #pass the var to space land

fi

}

rst

# var to keep amount of dirs desired to be done per run of script
# amount of files in the dir may not allow to get done in one day 
 amount_of_dir_to_work_on=$ConvertNum

echo ""$working_dir" START - creating list of files"

# get all of the names of the base dir to change name  a var containing ampunt of basenamedir in last place here 
#   amount_of_dir_to_work_on this is gotten off of the command line

    find "$working_dir" -mindepth 1 -maxdepth 1 -type d | while [ $DirCountDn  -lt $amount_of_dir_to_work_on ] ; 
        do read DIRNAME;
                    echo "$DIRNAME"



                #get list of all files in dir and sub dir's of current Dir to work off of

                    MAXMP3="$(find "$DIRNAME" -type f -name "*.mp3" | wc -l)"
                    MAXFLAC="$(find "$DIRNAME" -type f -name "*.flac" | wc -l)"

                    echo;echo;echo
                    echo "amount of mp3 "$MAXMP3" in "$DIRNAME""


                    FilesCountInSecondLoop=$(($MAXMP3 + $MAXFLAC))
                    filesLeftToDo="$FilesCountInSecondLoop" 



                    echo "Just starting off"
                    echo "MAXMP3 is               : "$MAXMP3""
                    echo "MAXFLAC is              : "$MAXFLAC""
                    echo "FilesCountInSecondLoop  : "$FilesCountInSecondLoop""
                    echo "Files left to do        : "$filesLeftToDo""
                    echo "cycleThroughFilesCount  : "$cycleThroughFilesCount""


                                                                      # MAXMP3 starts with a number 
                                                                       #  if not equle to 
                                                                       # cycleThroughFilesCount starts with zero         
    find "$DIRNAME" -type f -name "*.*" | while [ $FilesCountInSecondLoop -ne $cycleThroughFilesCount ] ;
        do read FILENAME;



                    #Directory to put the files back into it after resampling is completed  

                    r=$FILENAME

                    c=$FILENAME
                    xpath=${c%/*} 
                    xbase=${c##*/}
                    xfext=${xbase##*.}
                    xpref=${xbase%.*}
                    path=${xpath}
                    pref=${xpref}
                    ext=${xfext}


                    #checks to see if varitable is empty meaning no files to that extention to 
                    #resample are left to do --
                    if [ -z "$ext" ]; then 
                        echo "all Done - dar eay."
                        exit 1
                    fi

        #############################
        ############################
        ###
        ### GET RID OF EVERYTHING THAT IS NOT A MP3 OR FLAC FILE
        ###
        ##############################################################


        #Checks each movie file to see if it is just a not needed sample of the move to regain file space by deleting it

                    for file in "${path}" ; do 
                    #   echo "in for loop ext1 is -> "$ext"" 

                        if [[ "$ext" != 'flac' && "$ext" != 'mp3' && "ext" != 'jpg' ]]; then

                        #   echo "in loop if statment ext is -> "$ext""
                        #  echo "Removing "$FILENAME""

                        removeme="$FILENAME"
                        rm -v "$removeme"

                        # set a different ext type so that it will not go into following if statement due to it is still a movie extention
                        # causes it to skip over and go to next file
                        ## ext1="foobar"

                        let InIfLoop++
                    #   echo "in IF Loop ="${InIfLoop}""
                        fi
                            let inLoop++
                            #echo "inside of loop ="${inLoop}"" 
                    done

                        let leftLoop++
                        #echo "left loop count = "$leftLoop""


        ####################
        ###
        ### START ON MP3 or FLAC FILE
        ###
        ###############################################


        #echo "Extention off before into first if statment "${ext}""
        # echo

                    if [[ "${ext}" == 'mp3' || "${ext}" == 'flac' ]] ; then 

                        echo;echo
                        echo $FILENAME " Looking to resample this FILE now!"
                        echo;echo

        #############################################################
        #get the metadata tags off the mp3's using exiftool-perl
        #################

                ALBUM1="`exiftool  -Album  "$FILENAME" -p '$Album'`"
                ARTIST1="`exiftool -Artist "$FILENAME" -p '$Artist'`"
                SongName="`exiftool  -Title  "$FILENAME" -p '$Title'`"
                TRACK1=""
                TRACK2=""
                TRACK1="`exiftool "-Track Number" "$FILENAME" -p '$TrackNumber'`"
                TRACK2="`exiftool  -Track  "$FILENAME" -p '$Track'`"

                #GENRE1="`exiftool  -Genre "$FILENAME" -p '$Genre'`"
            #   echo "track 1  -> "$TRACK1""
            #   echo "track 2  -> "$TRACK2""
                #gets the number off the left side of file name if any then
                # hopefully fixs it to tag track number in file

                number=${pref//[^0-9 ]/}
                number=${number%% *}
                number=${number%/*}
        #removes leading white space on both ends of string
                number="$(echo -e "${number}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"

            #   echo "NUMBER IS now = "$number""

                if [ -z "${TRACK1}" ] && [ -z "${TRACK2}" ] ; then  
                    id3v2 -T "$number" "${FILENAME}"
                    echo "aftering adding track"
                    TRACK1="`exiftool "-Track Number" "$FILENAME" -p '$TrackNumber'`"
                    TRACK2="`exiftool  -Track  "$FILENAME" -p '$Track'`"
                    echo "this is track1 "$TRACK1""
                    echo "This is TRACK2 "$TRACK2""
                    echo

                fi



    #replaces all the crap and the spaces 
    #between the names with an underscore
    #"${x// /_}" meaning "${varName//search pattern/replace with}"


     echo "GETTING OFF TAGS"
    #echo
     echo "ARTIST1 going in is "$ARTIST1""
            newArt="${ARTIST1// / }"
            newArt="${newArt#/*}"
            newArt=${newArt//[^A-Za-z&0-9"'" ]/ }
            newArt="$(echo -e "${newArt}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    #ensure only one space between each word
            newArt="$(echo -e "${newArt}" | sed -e 's/\s+/ /g')"
    #removes leading white space on both ends of string
            newArt="$(echo -e "${newArt}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
     echo "newArt comming out is -> "$newArt""


            newTit="${SongName// / }"
            newTit=${newTit//[^A-Za-z&0-9"'" ]/ }
    #Capitalizes each word
            newTit="$(echo -e "${newTit}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    #ensure only one space between each word
            newTit="$(echo -e "${newTit}" | sed -e 's/\s+/ /g')"
    #removes leading white space on both ends of string
            newTit="$(echo -e "${newTit}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    #echo "NEW TITLE comming out is"
     echo "$newTit"


    #echo "ALBUM1 going in is -> "$ALBUM1""
            newAlb="${ALBUM1%/*}" 
            newAlb=${newAlb//[^A-Za-z&0-9"'" ]/ }
    #Capitalizes each word
            newAlb="$(echo -e "${newAlb}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    #ensure only one space between each word
            newAlb="$(echo -e "${newAlb}" | sed -e 's/\s+/ /g')"
    #removes leading white space on both ends of string
            newAlb="$(echo -e "${newAlb}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
     echo "newAlb commming out is -> "${newAlb}""
    #echo "DONE GETTING OFF TAGS"
    #echo
    #strip the orginal file name off the path from FILENAME
        c=$FILENAME
        xpath=${c%/*} 
        xbase=${c##*/}
        xfext=${xbase##*.}
        xpref=${xbase%.*}
        path=${xpath}
        pref=${xpref}
        ext=${xfext}

    ####################################

        c=$FILENAME

    ##############################
    # if MP3 has no needed tag information then 
    # strips names off of directory folders then uses them
    # as artist/band -- and album names in tags before renaming mp3 file
    ##########################
    # echo "GETTING OFF OF DIRECTORIES"

    # echo "STARTING TO EXTRACT DIRECTORIES NAMES"
        file=${c##*/}
        album1=${c#*"${c%/*/"$file"}"/}
        Artist=${album1%/*}
        Artist1=${c#*"${c%/*/"$album1"}"/}
        album=${album1%%/*}
        Artist2=${Artist1%%/*}
    #    echo "right here YO"
        dir=${FILENAME#*/*/*/*/} 
        dir=${dir//\/*}
        echo "$dir"
    #rename directory
        NewDirectoryName="$dir" 
    #   echo "$NewDirectoryName"
        NewDirectoryName=${NewDirectoryName%%'('*}
        NewDirectoryName=${NewDirectoryName%%'320cbr'*}
        NewDirectoryName=${NewDirectoryName%'[Bubanee]'*}
        NewDirectoryName=${NewDirectoryName%'MP3'*}
        NewDirectoryName=${NewDirectoryName%'2CD'*}
        NewDirectoryName=${NewDirectoryName%'Discography'*}
        NewDirectoryName=${NewDirectoryName%'discography'*}
        NewDirectoryName=${NewDirectoryName//[^A-Za-z ]/ }
    #Capitalizes each word
        NewDirectoryName="$(echo -e "${NewDirectoryName}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    #ensure only one space between each word
        NewDirectoryName="$(echo -e "${NewDirectoryName}" | sed -e 's/\s+/ /g')"
    #removes leading white space on both ends of string
        NewDirectoryName="$(echo -e "${NewDirectoryName}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    #echo "newAlb after striaghtening it up -> "${newAlb}""
    #   echo "NewDirectoryName is --- -> "$NewDirectoryName""
    #   echo

        e=$FILENAME
        xpath=${e%/*} 
        xbase=${e##*/}
        xfext=${xbase##*.}
        xpref=${xbase%.*}
        path1=${xpath}
        pref1=${xpref}
        ext1=${xfext}

    # echo "song off directory is -> "$pref1""
        songTitle="${pref1}"
        songTitle=${songTitle//[^A-Za-z&0-9"'" ]/ }
    #Capitalizes each word
        songTitle="$(echo -e "${songTitle}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    #ensure only one space between each word
        songTitle="$(echo -e "${songTitle}" | sed -e 's/\s+/ /g')"
    #removes leading white space on both ends of string
        songTitle="$(echo -e "${songTitle}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    #   echo "newAlb after striaghtening it up -> "${newAlb}""
    #   echo "new songTitle is -> "$songTitle""

    #  echo "DONE GETTING OFF OF DIRECTORIES"
    #echo;echo;
        if [ -z "$ALBUM1" ] ; then
            id3v2 -A "$newAlb1" "${FILENAME}"
            echo "tagging Album tag to file is -> "$newAlb1" "
            echo
        fi

        if [ -z "$ARTIST1" ] ; then
            id3v2 -a "$Artist" "${FILENAME}"
            echo "tagging Artist tag to file is -> "$Artist" "
            newArt=$Artist
            echo
        fi

        if [ -z "$SongName" ] ; then
            id3v2 -t "$songTitle" "${FILENAME}"
            echo "tagging Title tag to file is -> "$songTitle" "
            newTit=$songTitle 
            echo
        fi


    # MAKING NEW FILE NAME 
    ###########################


        ALBUM1="`exiftool  -Album  "$FILENAME" -p '$Album'`"

    #   echo "JFSDFSDFSDFSDFSDFSDFSDFSDFSDF"


        function GetArt () {
            if [[ ! -n "$ARTIST" ]]; then
                Art=$((ARTIST))
                #echo " got someting "

                return $Art #pass the var to space land
            fi
        }
            GetArt
          echo "this is the newAt justbefore making newFIle "$newArt""
        newFile=""${newTit}" - "${newArt}".mp3"

    # get the size of the Orginal File and keep for later use
        FileSize1="`exiftool '-File Size'  "$FILENAME" -p '$FileSize'`"


    #if song was already resampled it skips it then goes onto next one
        echo "******************************************************************"
    # echo "this is old file name about to be checked if matches new FileName"
    # echo "right here -> "$pref" new File name -> "${newFile%.*}""
    # echo
    ## REMOVE the Extention off of NewFile to check string
    #   if [[ "$pref" != "${newFile%.*}" ]] ; then

         if [[ "$pref" == "${newFile%.*}" ]] ; then
       echo;echo
                echo "This file -> :: "${newFile%.*}" " :: has already been done, skipping""

                let cycleThroughFilesCount++
                let filesLeftToDo--
                echo "amount of mp3   : "$MAXMP3" in "$DIRNAME""
                echo "MP 3 left to do : "$filesLeftToDo""
                echo "MP3 done        : "$cycleThroughFilesCount"" 
                echo;echo
         else

    #######################################
    #
    # CHECK BITRATE of MP3 = 192 - 160 vbr
    # CHOP OFF ENDING .00000
    # STORE IN VAR for checking value
    #########################################



        if [[ "${ext1}" == 'mp3' ]] ; then
    #rateme="$(mp3info -r a -p "%r\n" "${FILENAME}")"
    #rateis="${rateme%.*}" # strip off period and everything to the right of it
            echo
            rateis="$(mp3info -r m -p "%r\n" "${FILENAME}")"
            echo "Bitrate for "$pref1"."$ext1" is $rateis"
            echo    
            echo "LameCheckRate is "$LameCheckRate""
            echo
            echo "flac_convert_brate is "$flac_convert_brate""
            echo;echo
        fi
            echo;echo
        putback=${r%/*}
        echo "THIS IS PUT BACK DIR = "$putback""
echo;echo;  echo;echo;  echo;echo;  echo;echo;  echo;echo
    ##############################################################
    # Resampling FLAC with LAME 99.9.5  
    ###
    ##

        if [[ "${ext}" == 'flac' ]] ; then
            echo "got Dflack file  "${pref}"."${ext}""
            echo "converting to "${flac_convert_brate}" /kbps mp3"
            echo

            flac -cd "$FILENAME" | lame -h -b "${flac_convert_brate}" - "$newFile" 

            echo;echo;
    # get new bitrate and spit it out to the terminal
            rateis="$(mp3info -r m -p "%r\n" "$script_dir"/"${newFile}")"
            echo "Bitrate of .. $newFile   .. is .. $rateis .."
            echo;echo

            eyeD3 -A "$newAlb" "${script_dir}"/"${newFile}"
            echo "added "$newAlb" tag to file"

            eyeD3 -a "$newArt" "${script_dir}"/"${newFile}"
            echo "added "$newArt" tag to file"

            eyeD3 -t "$songTitle" "${script_dir}"/"${newFile}"
            echo "added "$songTitle" tag to file" 


        if [[ ! -n "${TRACK1}" ]] ; then        
            eyeD3 -n "$TRACK2" "${script_dir}"/"${newFile}"
            echo "added T2 - "$TRACK2" tag to file" 

        else 
            eyeD3 -n "$TRACK1" "${script_dir}"/"${newFile}"
            echo "added T1 - "$TRACK1" tag to file" 

        fi

            eyeD3 -G "$GENRE1"  "${script_dir}"/"${newFile}"
            echo "added "$GENRE1" tag to file" 
            echo;echo
            echo "after insert info "
            echo;echo "after reasiging FLAC resmapling" echo
            echo
        fi

    ##############################################################
    # Resampling MP3  with LAME 99.9.5  
    ###
    #flack file resampled into a MP3 falls through here and gets moved too
    # if MP3 is out of limits then re-sample it if not then send it through
        if [[ "${ext}" == 'mp3' ]] ; then
    # start bitrate       128        start bitrate       160
            if [[ "${rateis}" -gt "${LameCheckRate}" ]] ; then


        lame -V2 -b"${LameLowEnd}" -B"${LameHighEnd}" -F --vbr-new -m j -q2 "$FILENAME" "$newFile"
            echo
            echo "MOVING FILES NOW!"
            echo
            echo "$newFile"
            echo
    ## Resampled file is newFile located in script dir
            rm -v "${FILENAME}"
            echo;echo
            mv -v "${script_dir}"/"${newFile}" "${putback}"
            echo
            fileplace="${putback}"/"${newFile}"
            id3v2 -A "$newAlb" "${fileplace}"
            id3v2 -a "$newArt" "${fileplace}"
            id3v2 -t "$newTit" "${fileplace}"
            echo;echo "after move"
            exiftool "${putback}"/"${newFile}"

            let filesLeftToDo--
            let cycleThroughFilesCount++
            echo;echo "mp3's done "$cycleThroughFilesCount""
            else
    # if MP3 is within limits then skip resmapling then just make 
    # a copy to move it 
    # to new directory/folder
    ## WORKING SCRIPT DIRECTORY !
            echo;echo "is not needing resampling"
            echo "$pref1"."$ext"
            echo;echo "new file name is -> "${newFile}""
            echo

    #if old file name changed the change it
            compareme="${putback}"/"${newFile}"
            if [[ "${FILENAME}" != "${compareme}" ]] ; then

            mv -v "${FILENAME}" "${putback}"/"${newFile}"
            echo;echo "after not needing resample"
            echo
            exiftool "${putback}"/"${newFile}"

            let filesLeftToDo--
            let cycleThroughFilesCount++
            echo;echo "mp3 done "$cycleThroughFilesCount""

            fi
            echo;echo


            eyeD3 -A "$newAlb" "${putback}"/"${newFile}"
            echo "Non resampled stats"
    #exiftool "${script_dir}"/"${newFile}"

        fi

fi # end first if


            echo "Total MP3's Files are      : "$MAXMP3""
            echo "Files done so far is       : "$cycleThroughFilesCount""
            echo "MP3's left to do are       : "$filesLeftToDo""

# echo "After mp3 resampling file ->"
# exiftool "${script_dir}"/"${newFile}"

# I use EXIFTOOL because it works on FLAC files too for
# extracting the information
    echo;echo;





# get the size of the finished file to show differece in size of file
    echo "putback is --------  "$putback""
    checkme=""${putback}"/"${newFile}"" 
    FileSize2="`exiftool '-File Size' "$checkme" -p '$FileSize'`"


    fi


fi # end checking string for done file 


###########################################
## DO THE MATH ON MEGABYTES SAVED #########
###########################################

# if it cathces a KB file then it throws off the math. adding
# this keeps MB rounded up to the nearest whole one MB. 
    echo
    Hold1=$FileSize1
    Hold2=$FileSize2

    k1="${Hold1#* }"
    echo ""$k1" -- k1"

    if [[ "$k1" == 'kB' ]] ; then
        MB1=1
    else
        MB1="${FileSize1% *}"
    fi

    k2="${Hold2#* }"
    echo ""$k2" -- k2"

    if [[ "$k2" == 'kB' ]] ; then
        MB2=1
    else
        MB2="${FileSize2% *}"
    fi


# if it cannot stat file -- file unfound - bad file - then put a 
# zero in place of nothing to keep the total 
    if [[ "$FileSize1" == "" ]] ; then
        MB1=0
    fi

    if [[ "$FileSize2" == "" ]] ; then
        MB2=0
    fi

        echo "  "$MB1"  MB1 - start size"
        echo "- "$MB2"  MB2 - ending size"

# doing math on MB's
        totalSaveOnFile=`echo $MB1 - $MB2 | bc`
    echo "----------"
    echo "  "$totalSaveOnFile" MB - regained space" 
    echo "%%%%%%%%%%%%%%%"
    echo
    #maxSaved=$(( totalSaveOnFile + maxSaved ))


    maxSaved=`echo $totalSaveOnFile + $maxSaved | bc`
    echo
    echo "%%%%%%%%%%%%%%%%%%"
    echo;echo;echo
                            echo "***************************************"
                            echo;echo;echo





                            echo "AT IF STATMENTS"

                            echo "FILENAME is "$FILENAME""
                            NEWFILENAME=${FILENAME%/*}
                            #DIRNAME=${DIRNAME#*/*/*/*/} 
                            #DIRNAME=${DIRNAME//\/*}
                            echo "DIRNAME is "$DIRNAME""


                            echo "before if to do it"
                            echo "FilesCountInSecondLoop : "$FilesCountInSecondLoop""
                            echo "MAXMP3                 : "$MAXMP3""

                            if [[ "$FilesCountInSecondLoop" == "$cycleThroughFilesCount" ]] ; then

                                    echo " in if fileCount check"
                                    echo " NEWFILENAME is  "${NEWFILENAME}""
                                    echo "new file is "${newFile}""
                                    ARTIST1="`exiftool -Artist "${NEWFILENAME}"/"${newFile}" -p '$Artist'`"
                                    NewDirName="$ARTIST1"
                                    echo "new dir name is "$NewDirName""
                                    echo "this is MP3Count - "$MP3Count""
                                    #var names for dir nd paths and string compair
                                    OldDirName="$DIRNAME"
                                    echo;echo "OldDirName "$OldDirName""
                                    stringOldDir=${DIRNAME#*/*/*/*/}                                
                                    stringOldDir=${stringOldDir//\/*}
                                    echo;echo "stringOldDir "$stringOldDir""
                                    stringNewDir="$NewDirName"
                                    echo;echo "stringNewDir "$stringNewDir""
                                    oldDirPathNewName=""$working_dir"/"$NewDirName""
                                    echo;echo "oldDirPathNewName "$oldDirPathNewName""

                                 # if orginal dir name does not equals artist Tag name
                                 # change the dir to Artist Tag name then move it

                                 if [[ "$stringOldDir" != "$stringNewDir" ]] ; then  
                                    echo "not = "$stringOldDir" to "$stringNewDir""
                                            #change name of dir to artist/band name
                                                echo "mv OldDirName "$OldDirName" to "$oldDirPathNewName""
                                                echo "Working dir "$working_dir""

                                                #change old dir name to new dir name
                                                mv -v "$OldDirName" "$oldDirPathNewName"

                                                #then check to be sure root dir to move it to is there
                                                if [[ ! -d "$move_to" ]] ; then
                                                        echo "inside if more to dir is there"
                                                        mkdir -v "$move_to" 
                                                        #then move the new dir name to a different
                                                        # place for safe keeping
                                                        echo;echo "just befor move "
                                                        echo "oldDirPathNewName "$oldDirPathNewName" move to "$move_to""
                                                        mv -vf "$oldDirPathNewName" "$move_to" 
                                                else
                                                    echo "ELSE oldDirPathNewName "$oldDirPathNewName" move to "$move_to""
                                                    #if dir already created then just move the new dir there
                                                            mv -vf "$oldDirPathNewName" "$move_to"
                                                fi
                                fi

                        #if old dir name matches Artist Tag then insure more to dir is there then move it there

                                if [[ "$stringOldDir" == "$stringNewDir" ]] ; then  
                                  echo "Match strings "$stringOldDir" and "$stringNewDir""
                                    if [[ ! -d "move_to" ]] ; then
                                        mkdir -v "$move_to"
                                        mv -vf "$OldDirName" "$move_to" 
                                    else
                                        mv -fv "$OldDirName" "$move_to" 
                                    fi

                                fi
                        fi



    done
    let DirCountDn++
                echo "Dir Count Dn "$DirCountDn"" 
                echo "******************************************" 
                echo;echo;echo

done #FOR DIR Names
uxserx-bw

检查是否在不同的desanation基本文件夹中已经创建了父目录,如果为true,则只需将其复制到其中,然后删除旧目录,否则将整个目录移动

                            ## check to see if other parent dir  is there if not then make it so
                            if [[ ! -d "$move_to" ]] ; then
                                mkdir -v "$move_to"
                            fi

                        # if old dir does not match new dir name then change it

                                 if [[ "$stringOldDir" != "$stringNewDir" ]] ; then  
                                    echo "not = "$stringOldDir" to "$stringNewDir""


                                            #change name of dir to artist/band name
                                                echo "mv OldDirName "$OldDirName" to "$oldDirPathNewName""


                                                #change old dir name to new dir name
                                                mv -v "$OldDirName" "$oldDirPathNewName"
                                fi


                        #check if other parent dir and artist are there if not handle it

                                if [[ ! -d "$move_to"/"$stringNewDir" ]] ; then

                                            echo "inside ck if move to parent / artist to dir is there"
                                            echo
                                            echo ""$move_to"/"$stringNewDir" is not there moving "$stringNewDir""
                                            echo                                    
                                            #then move the new dir name to a different
                                            # place for safe keeping
                                            echo
                                            echo;echo "just befor move "
                                            echo
                                            echo "oldDirPathNewName "$oldDirPathNewName" move to "$move_to""
                                            echo            
                                            mv -vf "$oldDirPathNewName" "$move_to"/"$stringNewDir" 
                                            echo            

                                else
                                            echo ""$move_to"/"$stringNewDir" is there moving within it into"
                                            echo
                                            echo "$move_to"/"$stringNewDir"
                                            echo
                                            moveinsideof="$oldDirPathNewName"
                                            echo
                                            cp -Rv "${moveinsideof}"/* "$move_to"/"$stringNewDir" 
                                            echo
                                            rm -rv "$oldDirPathNewName"
                                fi

            fi      

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

mv:无法删除目录:目录不为空

来自分类Dev

无法删除项目。目录不为空

来自分类Dev

mv:目录不为空

来自分类Dev

mv:目录不为空

来自分类Dev

“无法删除'some_directory':目录不为空”

来自分类Dev

Cobian / Filezilla-FTP-无法删除目录:目录不为空(点[文件名]错误)

来自分类Dev

删除目录时出错:目录不为空

来自分类Dev

如何删除不为空的整个目录?

来自分类Dev

shell查找-删除“目录不为空”

来自分类Dev

查找:禁止显示“目录不为空”

来自分类Dev

mv:“目录不为空”-如何将目录与`mv`合并?

来自分类Dev

即使目录不为空,此路径也会跳过空目录

来自分类Dev

删除文件和目录(即使不为空),但某些目录除外

来自分类Dev

无法循环直到结果不为空

来自分类Dev

无法获得不为空的输出

来自分类Dev

移动不为空的行以从Pandas的第一列开始

来自分类Dev

无法移动mysql的数据目录

来自分类Dev

如果给定目录不为空,如何执行Ansible任务?

来自分类Dev

为什么我用“ rm -rf”得到“目录不为空”?

来自分类Dev

Haskell 捕获目录不存在但不为空值

来自分类Dev

如果目录为空,请执行此操作;如果目录不为空,请执行此操作

来自分类Dev

尝试删除空目录时,为什么会出现“目录不为空”的提示?

来自分类Dev

如果 dataGridView 值不为空,则 XX 无法按预期工作

来自分类Dev

空参数不为空

来自分类Dev

无法移动目录中的多个文件

来自分类Dev

无法移动到现有目录

来自分类Dev

意外移动的encfs加密目录,无法解密

来自分类Dev

存储过程不为空,不为空或空间

来自分类Dev

为什么在使用rmdir时终端中出现“目录不为空”错误?

Related 相关文章

热门标签

归档