public/Rename-FootballFixtureArtifact.ps1

function Rename-FootballFixtureArtifact {
    <#
        .EXAMPLE
            Rename-FootballFixtureArtifac -Competition eng-premier -Date 2025-02-01 -Path C:\Users\colin\Desktop\sportsmonk
             
        #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Competition,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Date,
        
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            $FixtureFolderNames = Get-FootballFixtureFolderName -Competition $Competition -Date $Date -Path $Path
            $NewsFolders =@('multi-media','pre-match-news','post-match-news')

            foreach ($FixtureFolderName in $FixtureFolderNames) {

                Write-Warning "processing $FixtureFolderName."

                foreach ($NewsFolder in $NewsFolders) {

                    $FullPath = "$Path\fixture-artifact\$NewsFolder\$Competition\$Date\$FixtureFolderName"
                    $FullPathExists = Test-Path -Path $FullPath

                    if ($FullPathExists) {

                        $FixtureChildItems = Get-ChildItem -Path $FullPath -ErrorAction Stop

                        foreach ($FixtureChildItem in $FixtureChildItems) {

                            if ($($FixtureChildItem.Name) -like "$FixtureFolderName*") {

                                Write-Warning -Message "$($FixtureChildItem.FullName) has already been renamed."

                            }
                            else {

                                Rename-Item -Path $($FixtureChildItem.FullName) -NewName "$FixtureFolderName-$($FixtureChildItem.Name)" -Verbose

                            } # if

                        } # foreach

                    }
                    else {

                        Write-Warning -Message "$FullPathExists does not exist."

                    } # if
            
                } # foreach

            } # foreach

        }
        catch {

            $($FixtureChildItem.FullName)
            $_.Exception.Message

        } # trycatch

    } # process

} # function