title: Test-Path behavior in Powershell
body: <p>I'm trying to write a script in powershell to batch convert video files.</p>
  
  <p>The way I intend to use it is to go to some folder full of video files and run it. It uses a conversion program that can be run in "command-line mode" (named handbrake) and saves the converted files with "-android" appended to them before the file extension. For example, if I have a file named video1.avi in the folder, after running the script the folder has 2 files: video1.avi and video1-android.avi</p>
  
  <p>The reason I want to do this this way is so that I can check if, for each video file, there is a converted version of it (with -android appended to the name). And if so, skip the conversion for that file.</p>
  
  <p>And this is where I'm having touble. The problem is the Test-Path's behavior (the cmdlet I'm using to test if a file exists).</p>
  
  <p>What happens is, if the video file has an "unusual" name (for example in my case it's video[long].avi) Test-Path always returns False if you try to check if that file exists.</p>
  
  <p>An easy way for you to test this is for example to do this:</p>
  
  <p>Go to an empty folder,
  run notepad to create a file with "[" in its name: </p>
  
  <pre><code>&amp;notepad test[x].txt
  </code></pre>
  
  <p>Save the file</p>
  
  <p>then do this:</p>
  
  <pre><code>Get-ChildItem | ForEach-Object {Test-Path $_.FullName}
  </code></pre>
  
  <p>It does not return true! It should right? Well it doesn't if the file has "[" in its name (I didn't check for any other special characters)</p>
  
  <p>I've realized that if you escape the "[" and "]" it works</p>
  
  <pre><code>Test-Path 'test`[x`].txt'
  </code></pre>
  
  <p>returns true.</p>
  
  <p>How can I go around this issue? I want to be able to: given a BaseName of a file, append it "-android.avi" and check if a file with that name exists.</p>
  
  <p>Thanks,
  Rui</p>