title: File renaming with powershell
body: <p>Script is working almost how it is intended, still struggling with renaming duplicate files. I cannot figure out how to get it to name the files like </p>
  
  <blockquote>
    <p>filename(1).ext</p>
    
    <p>filename(2).ext</p>
  </blockquote>
  
  <p>the closest I have gotten was</p>
  
  <blockquote>
    <p>filename(1).ext</p>
    
    <p>filename(1)(2).ext</p>
  </blockquote>
  
  <pre><code> #region actual script
   $srcRoot = "C:\srcLocation"
   $dstRoot = "C:\dstLocation"
  
   $fileList = Get-ChildItem -Path $srcRoot -File -Force -Recurse
  
      foreach ($file in $fileList) {
  
  
      $fileName = $file.Name.ToUpper()
      $fileExt = $file.Extension.ToUpper()
       $dstFileName = $null
  
       switch -Regex ($fileName)
      {
     '[A-Z]{4}-[0-9]{3}' { $dstFileName = $fileName }
     '[A-Z]{4} [0-9]{3}' { $dstFileName = $fileName -replace '([A-Z]{4})\s([0-
      9]{3})','$1-$2' }
     '[A-Z]{4}[0-9]{3}' { $dstFileName = $fileName -replace '([A-Z]{4})([0-9]
      {3})','$1-$2'}
     Default { Write-Warning -Message "$fileName is not an expected filename" 
     }
     }
  
     if ($dstFileName) {
     $dstDir = $dstFileName.Split('.')[0].Substring(0,8)
     $dstPath = Join-Path -Path $dstRoot -ChildPath $dstDir
  
     if (-not (Test-Path -Path $dstPath)) {
         New-Item -Path $dstPath -ItemType Directory
     }
     $i = 1
     if (test-path $dstPath\$dstFileName){
             $dstFileName = $dstFileName.Split('.')[0] + "($i)" + $fileExt
  
     While (test-path $dstPath\$dstFileName){
          $i +=1
          $dstFileName = $dstFileName -replace 
  
     }
     }
  
  
     Write-Verbose "Moving $($file.FullName)"
     Move-Item -Path $($file.FullName) -Destination $dstPath\$dstFileName -
     ErrorAction Continue
     }
     }
     #endregion
  </code></pre>