1

Referring to What is the best way to do a substring in a batch file? I think the below should work.

FOR %%f IN (*.wav) DO CALL :runthis "%%f"
rem del temp.wav tmpfile
GOTO :EOF

:runthis
set "outdir=%~p1\output\"
copy "%~1" "%outdir%%~1"

The last command is supposed to dosomthing to all .wav files in current directory and output to existing sub-directory "output" keeping the original filename. Any idea where I'm going wrong?

Update1: Thanks, fixed the syntax. I didn't notice that %pI expands I to path only, didn't read carefully. Now what's wrong is that it's expanded with the "s

dosomething "11.wav" "\Users\t4\Desktop\Airlines\WavRepeaters\\outdir\"11.wav""

It should be something like::

dosomething "11.wav" c:\Users\t4\Desktop\Airlines\WavRepeaters\outdir\11.wav

Update2: %~dp1 - expands %1 to a drive letter and path only, without the quotations!

Community
  • 1
  • 1
naim5am
  • 1,334
  • 3
  • 17
  • 33

1 Answers1

1

The main problem seems to be the use of the parameters.

In :runthis you use the %~pI, but there isn't any %I.
Another pitfall are spaces in the filenames, then dosomething need quotes around the filename / path.

With some changes it should work

@echo off
FOR %%f IN (*.bat) DO CALL :runthis "%%~f"
rem del temp.wav tmpfile
GOTO :EOF

:runthis
set "outdir=%~p1\output\"
echo dosomthing "%~1" "%outdir%%~1"
goto :eof
jeb
  • 78,592
  • 17
  • 171
  • 225