File globbing with powershell

I was able to find similar topics but nothing that I could make do quite what I’d like.
I have several folders at C:\dstpath they are all named like


I have tons of files (and increasing) at c:\srcpath

APPL-123 NameCont
APPL 123 NameCont
PINE-567 NameCont
PINE 567 NameCont

I would like a PowerShell script that checks C:\srcpath and renames all APPL 123, PINE 567 to APPL-123 etc. The file names always have a prefix of 4 letters, a space or hyphen, 3 numbers, then the rest of the file name. I would then like the file moved to the folder with the appropriate prefix in c:\dstpath. If that directory doesn’t exist then I would like one created. There are two source locations, however I can just use two scripts if needed. The destination is the same.

There are some files in the source locations that do not contain such prefixes (or similar words/numbers) I do not want these to be moved or a new directory created for them.

I used to run a simple cmd script move C:\srcpath APPL-123* C:\dstpath\APPL-123 however I wanted something a little more automatic, and I figured i’d learn a little more about PowerShell.

I read up on file globbing and came up with this, but it isn’t much more effective than the cmd script. Thank you for your time and help in advance.

$srcRoot = "C:\dstpath"
$dstRoot = "C:\srcpath"

$map = @{
    "APPL-123" = "APPL-123"
    "APPL 123" = "APPL-123"
    "PINE 567" = "PINE-567"          

$fileList = Get-ChildItem -Path $srcRoot -File -Force -Recurse

foreach ($file in $fileList) {
    $key = $file.BaseName.substring(0, 8)
    if ($key -in $map.Keys) {
        $fileName = $file.Name
        $dstDir = Join-Path -Path $dstRoot -ChildPath $map[$key]
        # Create destination directory if needed
        if (-not (Test-Path -Path $dstDir)) {
            mkdir -Path $dstDir
        Write-Verbose "Moving $($file.FullName)"
        if (Test-Path -Path (Join-Path -Path $dstDir -ChildPath $fileName)) {
            Write-Error -Message "File $fileName already exists at $dstDir"
        } else {
            Move-Item -Path $($file.FullName) -Destination $dstDir


File globbing with powershell