开发者

write files to relative path in DOS batch script

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开发者_如何学JAVA %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!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜