链接的问题可能有助于我的查询的上下文: 获取批处理循环的文件名
我只是没有赶上替代规则,但我认为这是一个类似的答案的问题…
我正在尝试使用下面的批次序列进行同样的移动操作。 任何人都可以帮助我纠正语法?
@echo off set source=C:Usersmy namesome long path with spaces set target=C:Usersmy namea different long path with spaces for %%F in ("%source%") do if not exist "%target%%~nF.jpg" copy "%%F" "%target%%~nF.jpg"
这个想法是把所有没有扩展名的文件复制到具有正确扩展名的目的地,其中具有匹配文件名的目的地以特定扩展名存在 在此先感谢任何人都可以协助!
升级Windows的DOSbatch file
使用batch filesearch.txt文件中的双字
批处理不识别回显
编辑:谢谢你的参考丹尼尔,但我不想复制文件名与目标匹配的扩展名。 我试图复制文件名到相同的文件名与新的扩展名
例:
sourcefilename001 destinationfilename001.jpg - do nothing sourcefilename002 destination{no match} - copy sourcefilename002 to destinationfilename002.jpg
亚历克斯,我不知道该怎么做。 我在没有回声的情况下查看输出,这就是为什么我发布这个问题。 我不明白如何修改替代才能正常工作。
for %%~F in ("%source%") do if not exist "%target%%~nF.jpg" copy "%%F" "%target%%~nF.jpg"
以下用于批量参数replace的path运算符是无效的:%〜nF.jpg“copy”%% F“”%target%%〜nF.jpg“
for %%F in ("%source%") do if not exist "%target%%~nF.jpg" copy "%%~F" "%target%%~nF.jpg"
批处理参数replace中path运算符的以下用法无效:%〜nF.jpg“copy”%%〜F“”%target%%〜nF.jpg“
set "source=C:Usersmy namesome long path with spaces" set "target=C:Usersmy namea different long path with spaces" for /F "delims=" %%F in ( 'Dir /B "%source%*." ' ) do if not exist "%target%%%~nF.jpg" copy "%source%%%~F" "%target%%%~nF.jpg"
如何在windowsbatch file中使用regexp来启动安装?
在Windows中结合mkv(自动化,不使用GUI)
批命令使用“@”
批量脚本检查Windows 7激活
从批处理中删除多个进程
MC ND有点快,但是你只能选择没有扩展名的源文件,所以我建议:
@echo off set source=C:Usersmy namesome long path with spaces set target=C:Usersmy namea different long path with spaces for /F "delims=" %%F in ( 'Dir /B "%source%*." ' ) do if not exist "%target%%%~nF.jpg" copy "%%F" "%target%%%~nF.jpg"
你的问题是在批处理文件中for可替换参数(保存被迭代元素的引用的变量 )需要在两个百分号( %%F )之前,包括使用任何修饰符(例如文件name = %%~nF )。
在命令行中,可替换参数只使用一个% ,而你的代码包含一些为批处理文件编写的引用,一些为命令行编写。
for %%F in ("%source%") do ^^^ for replaceable parameter in batch file,double % if not exist "%target%%~nF.jpg" copy "%%F" "%target%%~nF.jpg" ^^^^ ^^^^ for replaceable parameters missing a % (usage in command line)
所以,要解决它
@echo off set "source=C:Usersmy namesome long path with spaces" set "target=C:Usersmy namea different long path with spaces" for %%F in ("%source%*.") do if not exist "%target%%%~nF.jpg" copy "%%~F" "%target%%%~nF.jpg"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。