title: Move specific extension files and check for duplicate to change name if there is
body: <p>I try to build a function to move file with a specific extension and I want to check if there is a duplicate file in the destination repo. When I run this script it seem's like it go directly to else when I setup a copy of the file to move from source to destination in the destination. Could someone explain me why and how to fix it</p>
  <pre><code>   function deplacer_dossier {
      
          $files = Get-ChildItem -Path C:\mestp\mesFichiers *.mp3
              Foreach ($file in $files) 
              {
                  $fileexists = Test-Path C:\mestp\media\audio\$file
                  if($fileexists) {
                      $i = 1
                      $NewName = $file.BaseName + &quot;_&quot; + $i + $file.extension
                      $NewName | Move-Item -Destination &quot;C:\mestp\media\audio&quot;
                  }
                  else {
                      $file | Move-Item -Destination &quot;C:\mestp\media\audio&quot;
                  }    
              }
      
      }
  
  
  
  Move-Item: D:\Documents\AEC Réseautique &amp; Cybersécurité\420-E17-RI PROJET INTÉGRATEUR\TP1_Part1.ps1:43:25
  Line |
    43 |                  $file | Move-Item -Destination &quot;C:\mestp\media\audio&quot;
       |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       | Cannot create a file when that file already exists.
  </code></pre>