在DOS批处理脚本中将文件写入相对路径
参考什么是最好的如何在批处理文件中执行子字符串? 我认为下面的方法应该可行。
FOR %%f IN (*.wav) DO CALL :runthis "%%f"
rem del temp.wav tmpfile
GOTO :EOF
:runthis
set "outdir=%~p1\output\"
copy "%~1" "%outdir%%~1"
最后一个命令应该对当前目录中的所有 .wav 文件进行dosomthing,并输出到现有子目录“输出”,并保留原始文件名。知道我哪里出错了吗?
更新1:谢谢,修复了语法。我没有注意到 %pI 仅将 I 扩展为路径,没有仔细阅读。现在的问题是它用 "s 扩展
dosomething "11.wav" "\Users\t4\Desktop\Airlines\WavRepeaters\\outdir\"11.wav""
它应该类似于::
dosomething "11.wav" c:\Users\t4\Desktop\Airlines\WavRepeaters\outdir\11.wav
Update2: %~dp1 - 仅将 %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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主要问题似乎是参数的使用。
在 :runthis 中,您使用
%~pI
,但没有任何%I
。另一个陷阱是文件名中的空格,然后需要在文件名/路径周围加上引号。
经过一些改变,它应该可以工作
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