title: Batch - mkdir gives "filename, directory name or volume syntax is incorrect" in loop
body: <p>I am trying to make batch file for converting and copying files, while keeping the hierarchy of subfolders.</p>
  
  <p>My code so far (the troublesome part) is:</p>
  
  <pre><code>cd "%inputdir%"
  setlocal disableDelayedExpansion
  for /f "delims=" %%A in ('forfiles /s /m *.tga /c "cmd /c echo @relpath"') do (
    set "file=%%~A"
    setlocal enableDelayedExpansion
    echo !file:~1,-4!
    echo %inputdir%!file:~1!
    set filenametmp=%outputdir%!file:~1,-4!.paa
    echo %outputdir%!file:~1,-4!.paa
  
    For %%A in ("%filenametmp%") do (
      Set foldertmp=%%~dpA
    )
  
    IF NOT EXIST "%foldertmp%" (
    mkdir "%foldertmp%"
    ) 
    endlocal
  )
  </code></pre>
  
  <p>Problem is the part with creating folder. The echo under setting filename tmp gives "C:\Users\Asheara\Desktop\cicik\BI\M14\data\M14_body_CO.paa", which is correct</p>
  
  <p>For under it should get a directory part of the path ("C:\Users\Asheara\Desktop\cicik\BI\M14\data") and it works if i do:</p>
  
  <pre><code>For %%A in ("C:\Users\Asheara\Desktop\cicik\BI\M14\data\M14_body_CO.paa") do (
      Set foldertmp=%%~dpA
  )
  </code></pre>
  
  <p>before the loop (above the code i pasted before). However inside this loop it always throws this error, though the for itself and input data are the same.</p>
  
  <p>Does anyone know how to deal with this issue?
  Thanks</p>
  
  <p>EDIT:
  This is the working result:</p>
  
  <pre><code>cd "%inputdir%"
  setlocal disableDelayedExpansion
  for /f "delims=" %%A in ('forfiles /s /m *.tga /c "cmd /c echo @relpath"') do (
    set "file=%%~A"
    setlocal enableDelayedExpansion
    set filenametmp=%outputdir%!file:~1,-4!.paa
  
    setlocal enableDelayedExpansion
    For %%A in ("!filenametmp!") do (
      Set foldertmp=%%~dpA
    )
  
    setlocal enableDelayedExpansion
    IF NOT EXIST "!foldertmp!" (
      mkdir "!foldertmp!"
    )
    endlocal
  )
  </code></pre>