0

the Objective is to write a proccess that literates through a tree then change the names of everything within that tree including the names of the tree itself (the leafs, the branches, and trunk of the tree) without throwing an error.

this is the tree structor (a working example)

 [userx@(none) ~]$ tree /home/userx/testing
    /home/userx/testing
    └── Squeeze - 9 Albums FLAC ANDYT1000 KAT
    ├── Argybargy
    │   ├── 01. Pulling Mussels (From The Shell).flac
    │   ├── 02. Another Nail In My Heart.flac
    │   ├── 03. Separate Beds.flac
    │   ├── 04. Misadventure.flac
    │   ├── 05. I Think I'm Go Go.flac
    │   ├── 06. Farfisa Beat.flac
    │   ├── 07. Here Comes That Feeling.flac
    │   ├── 08. Vicky Verky.flac
    │   ├── 09. If I Didn't Love You.flac
    │   ├── 10. Wrong Side Of The Moon.flac
    │   ├── 11. There At The Top.flac
    │   ├── 12. Funny How It Goes.flac
    │   ├── 13. Go.flac
    │   ├── Argybargy.cuetools.flac.cue
    │   ├── Cover.jpg
    │   └── artwork
    │       ├── cover fold.jpg
    │       ├── disc.jpg
    │       ├── inlay.jpg
    │       ├── inner fold.jpg
    │       └── inner inlay.jpg
    ├── Big Squeeze  - The Very Best Of
    │   ├── CD 1
    │   │   ├── 01 Squeeze - Take Me, I'm Yours.flac
    │   │   ├── 02 Squeeze - Goodbye Girl.flac
    │   │   ├── 03 Squeeze - Cool for Cats.flac
    │   │   ├── 04 Squeeze - Up the Junction.flac
    │   │   ├── 05 Squeeze - Slap & Tickle.flac
    │   │   ├── 06 Squeeze - Another Nail in My Heart.flac
    │   │   ├── 07 Squeeze - Pulling Mussels (From the Shell).flac
    │   │   ├── 08 Squeeze - Is That Love.flac
    │   │   ├── 09 Squeeze - Tempted.flac
    │   │   ├── 10 Squeeze - Black Coffee in Bed.flac
    │   │   ├── 11 Squeeze - Annie Get Your Gun.flac
    │   │   ├── 12 Squeeze - Labelled with Love.flac
    │   │   ├── 13 Squeeze - Last Time Forever.flac
    │   │   ├── 14 Squeeze - Hourglass.flac
    │   │   ├── 15 Squeeze - Some Fantastic Place.flac
    │   │   ├── 16 Squeeze - Third Rail.flac
    │   │   ├── 17 Squeeze - This Summer.flac
    │   │   ├── 18 Squeeze - Electric Trains.flac
    │   │   ├── 19 Squeeze - Heaven Knows.flac
    │   │   ├── 20 Squeeze - Domino.flac
    │   │   ├── CD 1.cuetools.flac.cue
    │   │   └── Folder.jpg
    │   └── CD 2 The B Sides
    │       ├── 01 Squeeze - Suites from Five Strangers.flac
    │       ├── 02 Squeeze - Squabs on Forty Fab.flac
    │       ├── 03 Squeeze - Model.flac
    │       ├── 04 Squeeze - Spanish Guitar.flac
    │       ├── 05 Squeeze - Elephant Girl.flac
    │       ├── 06 Squeeze - Trust.flac
    │       ├── 07 Squeeze - Yap, Yap, Yap.flac
    │       ├── 08 Squeeze - The Fortnight Saga.flac
    │       ├── 09 Squeeze - Wedding Bells.flac
    │       ├── 10 Squeeze - What the Butler Saw.flac
    │       ├── 11 Squeeze - Going Crazy.flac
    │       ├── 12 Squeeze - Introvert.flac
    │       ├── 13 Squeeze - Who's That¿.flac
    │       ├── 14 Squeeze - Vanity Fair.flac
    │       ├── 15 Squeeze - Christmas Day.flac
    │       ├── 16 Squeeze - Maidstone.flac
    │       ├── 17 Squeeze - Discipline.flac
    │       ├── 18 Squeeze - Periscope.flac
    │       ├── 19 Squeeze - All's Well.flac
    │       ├── CD 2 The B Sides.cd2.cuetools.flac.cue
    │       └── Folder.jpg
    ├── Cool For Cats
    │   ├── 01. Slap And Tickle.flac
    │   ├── 02. Revue.flac
    │   ├── 03. Touching Me Touching You.flac
    │   ├── 04. It's Not Cricket.flac
    │   ├── 05. It's So Dirty.flac
    │   ├── 06. The Knack.flac
    │   ├── 07. Hop Skip And Jump.flac
    │   ├── 08. Up The Junction.flac
    │   ├── 09. Hard To Find.flac
    │   ├── 10. Slightly Drunk.flac
    │   ├── 11. Goodbye Girl.flac
    │   ├── 12. Cool For Cats.flac
    │   ├── 13. I Must Go.flac
    │   ├── 14. Ain't It Sad.flac
    │   ├── Cool For Cats.cuetools.flac.cue
    │   └── Cover.jpg
    ├── Cosi Fan Tutti Frutti
    │   ├── 01. Big Beng.flac
    │   ├── 02. By Your Side.flac
    │   ├── 03. King George Street.flac
    │   ├── 04. I Learnt How To Pray.flac
    │   ├── 05. Last Time Forever.flac
    │   ├── 06. No Place Like Home.flac
    │   ├── 07. Heartbreaking World.flac
    │   ├── 08. Hits Of The Year.flac
    │   ├── 09. Break My Heart.flac
    │   ├── 10. I Won't Ever Go Drinking Again.flac
    │   ├── 11. Love's A Four Letter Word [Bonus].flac
    │   ├── 12. The Fortnight Saga [Bonus].flac
    │   ├── Cosi Fan Tutti Frutti.cuetools.flac.cue
    │   └── Cover.jpg
    ├── Domino
    │   ├── 01. Play On.flac
    │   ├── 02. Bonkers.flac
    │   ├── 03. What's Wrong With This Picture.flac
    │   ├── 04. Domino.flac
    │   ├── 05. To Be A Dad.flac
    │   ├── 06. Donkey Talk.flac
    │   ├── 07. Sleeping With A Friend.flac
    │   ├── 08. Without You Here.flac
    │   ├── 09. In The Morning.flac
    │   ├── 10. A Moving Story.flac
    │   ├── 11. Little King.flac
    │   ├── 12. Short Break.flac
    │   ├── Cover.jpg
    │   └── Domino.cuetools.flac.cue
    ├── East Side Story
    │   ├── 01. In Quintessence.flac
    │   ├── 02. Someone Else's Heart.flac
    │   ├── 03. Tempted.flac
    │   ├── 04. Piccadilly.flac
    │   ├── 05. There's No Tomorrow.flac
    │   ├── 06. Heaven.flac
    │   ├── 07. Woman's World.flac
    │   ├── 08. Is That Love.flac
    │   ├── 09. F-Hole.flac
    │   ├── 10. Labelled With Love.flac
    │   ├── 11. Someone Else's Bell.flac
    │   ├── 12. Mumbo Jumbo.flac
    │   ├── 13. Vanity Fair.flac
    │   ├── 14. Messed Around.flac
    │   ├── 15. The Axe Has Now Fallen [Bonus].flac
    │   ├── 16. Looking For A Love [Bonus].flac
    │   ├── Cover.jpg
    │   └── East Side Story.cuetools.flac.cue
    ├── Piccadilly Collection
    │   ├── 01. Everything In The World.flac
    │   ├── 02. Some Fantastic Place.flac
    │   ├── 03. Loving You Tonight.flac
    │   ├── 04. If It's Love.flac
    │   ├── 05. Within These Walls.flac
    │   ├── 06. What The Butler Saw.flac
    │   ├── 07. Squabs On The Forty Fab.flac
    │   ├── 08. Pulling Mussels (From The Shell).flac
    │   ├── 09. Hourglass.flac
    │   ├── 10. Tempted.flac
    │   ├── 11. Black Coffee In Bed.flac
    │   ├── 12. Elephant Girl.flac
    │   ├── 13. Spanish Guitar.flac
    │   ├── 14. Annie Get Your Gun.flac
    │   ├── 15. Love's Crashing Waves.flac
    │   ├── 16. Hope Fell Down.flac
    │   ├── 17. (This Could Be) The Last Time.flac
    │   ├── 18. Last Time Forever.flac
    │   ├── Cover.jpg
    │   └── Piccadilly Collection.cuetools.flac.cue
    ├── Squeeze
    │   ├── 01. Sex Master.flac
    │   ├── 02. Bang Bang.flac
    │   ├── 03. Strong In Reason.flac
    │   ├── 04. Wild Sewerage Tickles Brazil.flac
    │   ├── 05. Out Of Control.flac
    │   ├── 06. Take Me, I'm Yours.flac
    │   ├── 07. The Call.flac
    │   ├── 08. Model.flac
    │   ├── 09. Remember What.flac
    │   ├── 10. First Thing Wrong.flac
    │   ├── 11. Hesitation (Rool Britannia).flac
    │   ├── 12. Get Smart.flac
    │   ├── 13. Deep Cuts.flac
    │   ├── 14. Heartbreak.flac
    │   ├── Cover.jpg
    │   ├── Squeeze.cuetools.flac.cue
    │   └── artwork
    │       ├── cover fold.jpg
    │       ├── disc.jpg
    │       ├── inlay.jpg
    │       ├── inner fold.jpg
    │       └── inner inlay.jpg
    └── Sweets From A Stranger
        ├── 01. Out Of Touch.flac
        ├── 02. I Can't Hold On.flac
        ├── 03. Points Of View.flac
        ├── 04. Stranger Than The Stranger On The Shore.flac
        ├── 05. Onto The Dance Floor.flac
        ├── 06. When The Hangover Strikes.flac
        ├── 07. Black Coffee In Bed.flac
        ├── 08. I've Returned.flac
        ├── 09. Tongue Like A Knife.flac
        ├── 10. His House Her Home.flac
        ├── 11. The Very First Dance.flac
        ├── 12. The Elephant Ride.flac
        ├── 13. I Can't Get Up Anymore [Bonus].flac
        ├── 14. When Love Goes To Sleep [Bonus].flac
        ├── Cover.jpg
        ├── Sweets From A Stranger.cuetools.flac.cue
        └── artwork
            ├── cover fold.jpg
            ├── disc.jpg
            ├── inlay.jpg
            ├── inner fold.jpg
            └── inner inlay.jpg

    15 directories, 187 files

what I have so far literates through the tree and changes the names of all of the files, but not the names of all of the branches (directory names) just the, I think it would be called is the basename of the tree being this one, Squeeze_9_Albums_FLAC_ANDYT1000_KAT

that is the only directory name that is changed. as we can see.

[userx@(none) ~]$ tree /home/userx/testing
/home/userx/testing
└── Squeeze_9_Albums_FLAC_ANDYT1000_KAT
    ├── Argybargy
    │   ├── 01.-Pulling-Mussels-(From-The-Shell).flac
    │   ├── 02.-Another-Nail-In-My-Heart.flac
    │   ├── 03.-Separate-Beds.flac
    │   ├── 04.-Misadventure.flac
    │   ├── 05.-I-Think-I'm-Go-Go.flac
    │   ├── 06.-Farfisa-Beat.flac
    │   ├── 07.-Here-Comes-That-Feeling.flac
    │   ├── 08.-Vicky-Verky.flac
    │   ├── 09.-If-I-Didn't-Love-You.flac
    │   ├── 10.-Wrong-Side-Of-The-Moon.flac
    │   ├── 11.-There-At-The-Top.flac
    │   ├── 12.-Funny-How-It-Goes.flac
    │   ├── 13.-Go.flac
    │   ├── Argybargy.cuetools.flac.cue
    │   ├── Cover.jpg
    │   └── artwork
    │       ├── cover-fold.jpg
    │       ├── disc.jpg
    │       ├── inlay.jpg
    │       ├── inner-fold.jpg
    │       └── inner-inlay.jpg
    ├── Big Squeeze  - The Very Best Of
    │   ├── CD 1
    │   │   ├── 01-Squeeze-Take-Me,-I'm-Yours.flac
    │   │   ├── 02-Squeeze-Goodbye-Girl.flac
    │   │   ├── 03-Squeeze-Cool-for-Cats.flac
    │   │   ├── 04-Squeeze-Up-the-Junction.flac
    │   │   ├── 05-Squeeze-Slap-&-Tickle.flac
    │   │   ├── 06-Squeeze-Another-Nail-in-My-Heart.flac
    │   │   ├── 07-Squeeze-Pulling-Mussels-(From-the-Shell).flac
    │   │   ├── 08-Squeeze-Is-That-Love.flac
    │   │   ├── 09-Squeeze-Tempted.flac
    │   │   ├── 10-Squeeze-Black-Coffee-in-Bed.flac
    │   │   ├── 11-Squeeze-Annie-Get-Your-Gun.flac
    │   │   ├── 12-Squeeze-Labelled-with-Love.flac
    │   │   ├── 13-Squeeze-Last-Time-Forever.flac
    │   │   ├── 14-Squeeze-Hourglass.flac
    │   │   ├── 15-Squeeze-Some-Fantastic-Place.flac
    │   │   ├── 16-Squeeze-Third-Rail.flac
    │   │   ├── 17-Squeeze-This-Summer.flac
    │   │   ├── 18-Squeeze-Electric-Trains.flac
    │   │   ├── 19-Squeeze-Heaven-Knows.flac
    │   │   ├── 20-Squeeze-Domino.flac
    │   │   ├── CD-1.cuetools.flac.cue
    │   │   └── Folder.jpg
    │   └── CD 2 The B Sides
    │       ├── 01-Squeeze-Suites-from-Five-Strangers.flac
    │       ├── 02-Squeeze-Squabs-on-Forty-Fab.flac
    │       ├── 03-Squeeze-Model.flac
    │       ├── 04-Squeeze-Spanish-Guitar.flac
    │       ├── 05-Squeeze-Elephant-Girl.flac
    │       ├── 06-Squeeze-Trust.flac
    │       ├── 07-Squeeze-Yap,-Yap,-Yap.flac
    │       ├── 08-Squeeze-The-Fortnight-Saga.flac
    │       ├── 09-Squeeze-Wedding-Bells.flac
    │       ├── 10-Squeeze-What-the-Butler-Saw.flac
    │       ├── 11-Squeeze-Going-Crazy.flac
    │       ├── 12-Squeeze-Introvert.flac
    │       ├── 13-Squeeze-Who's-That¿.flac
    │       ├── 14-Squeeze-Vanity-Fair.flac
    │       ├── 15-Squeeze-Christmas-Day.flac
    │       ├── 16-Squeeze-Maidstone.flac
    │       ├── 17-Squeeze-Discipline.flac
    │       ├── 18-Squeeze-Periscope.flac
    │       ├── 19-Squeeze-All's-Well.flac
    │       ├── CD-2-The-B-Sides.cd2.cuetools.flac.cue
    │       └── Folder.jpg
    ├── Cool For Cats
    │   ├── 01.-Slap-And-Tickle.flac
    │   ├── 02.-Revue.flac
    │   ├── 03.-Touching-Me-Touching-You.flac
    │   ├── 04.-It's-Not-Cricket.flac
    │   ├── 05.-It's-So-Dirty.flac
    │   ├── 06.-The-Knack.flac
    │   ├── 07.-Hop-Skip-And-Jump.flac
    │   ├── 08.-Up-The-Junction.flac
    │   ├── 09.-Hard-To-Find.flac
    │   ├── 10.-Slightly-Drunk.flac
    │   ├── 11.-Goodbye-Girl.flac
    │   ├── 12.-Cool-For-Cats.flac
    │   ├── 13.-I-Must-Go.flac
    │   ├── 14.-Ain't-It-Sad.flac
    │   ├── Cool-For-Cats.cuetools.flac.cue
    │   └── Cover.jpg
    ├── Cosi Fan Tutti Frutti
    │   ├── 01.-Big-Beng.flac
    │   ├── 02.-By-Your-Side.flac
    │   ├── 03.-King-George-Street.flac
    │   ├── 04.-I-Learnt-How-To-Pray.flac
    │   ├── 05.-Last-Time-Forever.flac
    │   ├── 06.-No-Place-Like-Home.flac
    │   ├── 07.-Heartbreaking-World.flac
    │   ├── 08.-Hits-Of-The-Year.flac
    │   ├── 09.-Break-My-Heart.flac
    │   ├── 10.-I-Won't-Ever-Go-Drinking-Again.flac
    │   ├── 11.-Love's-A-Four-Letter-Word-[Bonus].flac
    │   ├── 12.-The-Fortnight-Saga-[Bonus].flac
    │   ├── Cosi-Fan-Tutti-Frutti.cuetools.flac.cue
    │   └── Cover.jpg
    ├── Domino
    │   ├── 01.-Play-On.flac
    │   ├── 02.-Bonkers.flac
    │   ├── 03.-What's-Wrong-With-This-Picture.flac
    │   ├── 04.-Domino.flac
    │   ├── 05.-To-Be-A-Dad.flac
    │   ├── 06.-Donkey-Talk.flac
    │   ├── 07.-Sleeping-With-A-Friend.flac
    │   ├── 08.-Without-You-Here.flac
    │   ├── 09.-In-The-Morning.flac
    │   ├── 10.-A-Moving-Story.flac
    │   ├── 11.-Little-King.flac
    │   ├── 12.-Short-Break.flac
    │   ├── Cover.jpg
    │   └── Domino.cuetools.flac.cue
    ├── East Side Story
    │   ├── 01.-In-Quintessence.flac
    │   ├── 02.-Someone-Else's-Heart.flac
    │   ├── 03.-Tempted.flac
    │   ├── 04.-Piccadilly.flac
    │   ├── 05.-There's-No-Tomorrow.flac
    │   ├── 06.-Heaven.flac
    │   ├── 07.-Woman's-World.flac
    │   ├── 08.-Is-That-Love.flac
    │   ├── 09.-F-Hole.flac
    │   ├── 10.-Labelled-With-Love.flac
    │   ├── 11.-Someone-Else's-Bell.flac
    │   ├── 12.-Mumbo-Jumbo.flac
    │   ├── 13.-Vanity-Fair.flac
    │   ├── 14.-Messed-Around.flac
    │   ├── 15.-The-Axe-Has-Now-Fallen-[Bonus].flac
    │   ├── 16.-Looking-For-A-Love-[Bonus].flac
    │   ├── Cover.jpg
    │   └── East-Side-Story.cuetools.flac.cue
    ├── Piccadilly Collection
    │   ├── 01.-Everything-In-The-World.flac
    │   ├── 02.-Some-Fantastic-Place.flac
    │   ├── 03.-Loving-You-Tonight.flac
    │   ├── 04.-If-It's-Love.flac
    │   ├── 05.-Within-These-Walls.flac
    │   ├── 06.-What-The-Butler-Saw.flac
    │   ├── 07.-Squabs-On-The-Forty-Fab.flac
    │   ├── 08.-Pulling-Mussels-(From-The-Shell).flac
    │   ├── 09.-Hourglass.flac
    │   ├── 10.-Tempted.flac
    │   ├── 11.-Black-Coffee-In-Bed.flac
    │   ├── 12.-Elephant-Girl.flac
    │   ├── 13.-Spanish-Guitar.flac
    │   ├── 14.-Annie-Get-Your-Gun.flac
    │   ├── 15.-Love's-Crashing-Waves.flac
    │   ├── 16.-Hope-Fell-Down.flac
    │   ├── 17.-(This-Could-Be)-The-Last-Time.flac
    │   ├── 18.-Last-Time-Forever.flac
    │   ├── Cover.jpg
    │   └── Piccadilly-Collection.cuetools.flac.cue
    ├── Squeeze
    │   ├── 01.-Sex-Master.flac
    │   ├── 02.-Bang-Bang.flac
    │   ├── 03.-Strong-In-Reason.flac
    │   ├── 04.-Wild-Sewerage-Tickles-Brazil.flac
    │   ├── 05.-Out-Of-Control.flac
    │   ├── 06.-Take-Me,-I'm-Yours.flac
    │   ├── 07.-The-Call.flac
    │   ├── 08.-Model.flac
    │   ├── 09.-Remember-What.flac
    │   ├── 10.-First-Thing-Wrong.flac
    │   ├── 11.-Hesitation-(Rool-Britannia).flac
    │   ├── 12.-Get-Smart.flac
    │   ├── 13.-Deep-Cuts.flac
    │   ├── 14.-Heartbreak.flac
    │   ├── Cover.jpg
    │   ├── Squeeze.cuetools.flac.cue
    │   └── artwork
    │       ├── cover-fold.jpg
    │       ├── disc.jpg
    │       ├── inlay.jpg
    │       ├── inner-fold.jpg
    │       └── inner-inlay.jpg
    └── Sweets From A Stranger
        ├── 01.-Out-Of-Touch.flac
        ├── 02.-I-Can't-Hold-On.flac
        ├── 03.-Points-Of-View.flac
        ├── 04.-Stranger-Than-The-Stranger-On-The-Shore.flac
        ├── 05.-Onto-The-Dance-Floor.flac
        ├── 06.-When-The-Hangover-Strikes.flac
        ├── 07.-Black-Coffee-In-Bed.flac
        ├── 08.-I've-Returned.flac
        ├── 09.-Tongue-Like-A-Knife.flac
        ├── 10.-His-House-Her-Home.flac
        ├── 11.-The-Very-First-Dance.flac
        ├── 12.-The-Elephant-Ride.flac
        ├── 13.-I-Can't-Get-Up-Anymore-[Bonus].flac
        ├── 14.-When-Love-Goes-To-Sleep-[Bonus].flac
        ├── Cover.jpg
        ├── Sweets-From-A-Stranger.cuetools.flac.cue
        └── artwork
            ├── cover-fold.jpg
            ├── disc.jpg
            ├── inlay.jpg
            ├── inner-fold.jpg
            └── inner-inlay.jpg

15 directories, 187 files

this is the script I wrote to do this:

    #!/bin/bash

#tues dec-29-2015

typeset -i Afiles count 

let Afiles=0 count=0 

echo ; echo ; echo 

working_dir="$HOME/testing"

script_dir="$HOME/scripts"

AmountDirs="$(find "$working_dir" -mindepth 1 -type d  | wc -l)"

find "$working_dir" -mindepth 1 -type d | while [[ $AmountDirs -gt $count ]] ; 
    do read DIRNAME;

            if [[ -z "$DIRNAME" ]] ; then
                echo "DIRNAME "$DIRNAME" is empty Yo"
                exit 0
            fi

    PDIR=${DIRNAME%/*}

    DIR=${DIRNAME##*/} 

    #clean up names according to what ever user wants to remove first
    DIR=${DIR%@*}

    DIR=${DIR//-/ }

    DIR=${DIR//_/ }

    #ensure only one space between each word

    DIR="$(echo -e "${DIR}" | fmt -u )"

    #removes leading white space on both ends of string

    DIR="$(echo -e "${DIR}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"

    #add to name what ever user wants to here
    DIR=${DIR// /_}

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

        MAX="$(find "$DIRNAME" -type f -name "*.*" | wc -l)"

    find "$DIRNAME" -type f -name "*.*" | while [ $Afiles -ne $MAX ] ;
        do read FILENAME;

        f=$FILENAME
        path=${f%/*}
        xfile=${f##*/}
        title=${xfile%.*}
        ext=${xfile##*.}

        #clean up names according to what ever user wants to remove first
        title=${title//-/ } 

        #ensure only one space between each word
        title="$(echo  -e "${title}" | fmt -u )"

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

        #add to name what ever user wants to here
        title=${title// /-}

        newTitle="$title"."$ext"

        let Afiles++
        echo
        mv -v "$FILENAME"  "$path"/"$newTitle"    


done
    echo    
    mv -v "$DIRNAME" "$PDIR"/"$DIR"  
    echo
    let count++
done 

I am not sure if one needs to see this but here it is just incase. If one looks at the end part of it, they will see where it is starting to throw errors -- dir not found, due to that "base dir" name change. I have no idea what it is trying to do at that point.

Sniplet of results on term

[userx@(none) scripts]$ ./changeTreeNames



mv: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Domino/Cover.jpg’ and ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Domino/Cover.jpg’ are the same file

‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Domino/01. Play On.flac’ -> ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Domino/01.-Play-On.flac’


‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides/19 Squeeze - All's Well.flac’ -> ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides/19-Squeeze-All's-Well.flac’

‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides/10 Squeeze - What the Butler Saw.flac’ -> ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides/10-Squeeze-What-the-Butler-Saw.flac’



mv: cannot stat ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of’: No such file or directory

find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides’: No such file or directory
find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides’: No such file or directory

mv: cannot stat ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 2 The B Sides’: No such file or directory

find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 1’: No such file or directory
find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 1’: No such file or directory

mv: cannot stat ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Big Squeeze  - The Very Best Of/CD 1’: No such file or directory

find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Piccadilly Collection’: No such file or directory
find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Piccadilly Collection’: No such file or directory

mv: cannot stat ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Piccadilly Collection’: No such file or directory

find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Cosi Fan Tutti Frutti’: No such file or directory
find: ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Cosi Fan Tutti Frutti’: No such file or directory

mv: cannot stat ‘/home/userx/testing/Squeeze - 9 Albums FLAC ANDYT1000 KAT/Cosi Fan Tutti Frutti’: No such file or directory

I know what it needs to do, after it gets done with all of the files within one directory then it needs to change that name that held all of them files first before moving on to the next directory to do the same. then when it has complete all of the then go to that basedir and change the name of that, not before like it is doing.

I do hope I have not confused anyone, chew on it for a bit before trying to give me your solution please, and thanks

uxserx-bw
  • 516
  • 3
  • 7
  • 22
  • pretty much -- it gives the abiltiy to change the names to what ever I or a user wants to. that is not really the problem. the problem is that it does not work on the directories in proper order – uxserx-bw Dec 30 '15 at 22:36
  • 1
    tl;dr. I think the -depth directive to find will take you a long way towards your goal. – glenn jackman Dec 30 '15 at 23:17
  • @glennjackman added it to the first loop, after I had to look what that does up, now its looking like it cycles through everything twice , giving me a same file error/warrning on everything on the tail end of running the script. lol – uxserx-bw Dec 30 '15 at 23:50
  • If you're on Ubuntu, you can probably do the whole thing with a single find command with a -exec rename operator and a regex passed to rename. If you're on RHEL/CentOS, still check that link, but you have a different version of rename and might still need your uber-long script. EDIT: Actually you will never ever ever need to do this much string parsing by juggling bash variables. Just use sed for that part. – Wildcard Dec 31 '15 at 00:12
  • @Wildcard I'm not on UBututut But that thought of just running it in "one line" and not using 2 loops was just passing through my mind. I am using VOID Linux, I'll be needing to do some reading up on regex and such -- I've been advoiding digging into the complexity of BASH to make is simpler .. guess I better quit hanging out in the girls locker room and smoking and move myself up to the next grade level to learn more stuff. ;) – uxserx-bw Dec 31 '15 at 00:23

1 Answers1

1

Try to use -depth find's switch and...

Use more quotes !

"Double quote" every literal that contains spaces/metacharacters and every expansion: "$var", "$(command "$var")", "${array[@]}", "a & b". Use 'single quotes' for code or literal $'s: 'Costs $5 US', ssh host 'echo "$HOSTNAME"'. See
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words

  • that code works on the files, not the directories (not that it worked in my loops, (copy past) I got the files ok it is the Directories that need to be changed. ;) – uxserx-bw Dec 30 '15 at 22:43
  • Not tested, but you should have sufficient stuff to fix the whole trick – Gilles Quénot Dec 30 '15 at 22:47
  • yes I bet you a cat you're right, but it looks to the files which are copastedic it is the directories that are OOO (Out Of Order) is all. thanks -- this -depth this someone else suggested seems to work leaving me only one error just as the script ends it tries to move the dir tree into itself. – uxserx-bw Dec 30 '15 at 23:33
  • Have you quoted your vars ? – Gilles Quénot Dec 30 '15 at 23:34
  • quoted and POSIX compliant. thanks for that information. it seems adding the -depth to the find on the first loop is working, I'm testing it again right now to be sure. Option: -depth Process each directory's contents before the directory itself. – uxserx-bw Dec 30 '15 at 23:40
  • typeset and let are outdated :) Check http://mywiki.wooledge.org/ArithmeticExpression – Gilles Quénot Dec 30 '15 at 23:52
  • that page in the very first paragraph of it is all about how to use LET - and nothing about typeset being one way or the other -- it works so why break it? – uxserx-bw Dec 31 '15 at 11:57
  • Doesn't matter. Just style concerned – Gilles Quénot Dec 31 '15 at 14:29
  • wonders what kind of stylish shoes he's wearing ;) hehe – uxserx-bw Jan 02 '16 at 15:10