title: How to clean-up file paths (back/forward slashes) provided as arguments in a .bat script to avoid syntax errors
body: <p>I have a simple .bat script which renames all files in a folder using <code>ren</code>. The input argument is a path to a folder containing the files to be renamed. The script sometimes returns syntax errors which we've traced to the fact that sometimes the input path has forward slashes, backslashes, or a mix of both (and sometimes starts with a double forward slash). We would like to make this script more robust by allowing it to accept any of these types of paths, and cleaning up the path as part of the .bat script before calling the <code>ren</code> command.</p>
  <p>So my question is: is there a (set of) command(s) I can apply to the file path argument (<code>%1</code> in the example below) before calling the <code>ren</code> function that will correct all forward/backslashes to be consistent and avoid syntax errors? I don't have much experience with .bat scripts, so any code examples would be helpful.</p>
  <pre><code>@echo off
  setlocal ENABLEDELAYEDEXPANSION
  for %%F in (%1*.nc) do (
     for /F &quot;tokens=1-8 delims=_&quot; %%a in (&quot;%%~nF&quot;) do (
     ren &quot;%%F&quot; &quot;%%a_%%b_%%c_%%d_%%e_%%g_%%f_%%h.nc&quot;
     ) 
  ) 
  </code></pre>
  <p>UPDATE: In the end, only the last suggestion by Magoo was needed, because changing <code>%1</code> to <code>&quot;%~f1&quot;</code> fixed the slash issues. I also had to add <code>%~f1\</code> to the first argument of the <code>ren</code> command because otherwise it was somehow looking in the wrong folder (the first <code>for</code> found the files ok, but the <code>ren</code> command was looking in the wrong folder.</p>
  <pre><code>@echo off
  setlocal ENABLEDELAYEDEXPANSION
  for /F &quot;delims=&quot; %%F in ('dir /b /a-d &quot;%~f1\*.nc&quot;') do (
     for /F &quot;tokens=1-8 delims=_&quot; %%a in (&quot;%%~nF&quot;) do (
     ren &quot;%~f1\%%~nF.nc&quot; &quot;%%a_%%b_%%c_%%d_%%e_%%g_%%f_%%h.nc&quot;
     ) 
  ) 
  </code></pre>