gpt4 book ai didi

windows - 批量复制唯一文件到新文件夹

转载 作者:可可西里 更新时间:2023-11-01 11:46:45 24 4
gpt4 key购买 nike

链接的问题可能有助于我查询的上下文:Get filename in batch for loop

我只是没有理解替换规则,但我认为这是一个具有相似答案的问题...

我正在尝试使用以下批处理序列执行相同类型的移动操作。谁能帮我纠正语法?

@echo off

set source=C:\Users\my name\some long path with spaces
set target=C:\Users\my name\a different long path with spaces

for %%F in ("%source%") do if not exist "%target%\%~nF.jpg" copy "%%F" "%target%\%~nF.jpg"

想法是将所有没有扩展名的文件复制到具有正确扩展名的目标中,其中存在具有特定扩展名的匹配文件名的目标。在此先感谢任何人都可以提供帮助!


编辑:感谢 Daniel 的引用,但我并没有尝试将文件名复制到具有匹配扩展名的目标。我正在尝试将文件名复制到具有新扩展名的相同文件名

例子:

source\filename001
destination\filename001.jpg
- do nothing
source\filename002
destination\{no match}
- copy source\filename002 to destination\filename002.jpg

亚历克斯,我不确定接下来该做什么。我在没有回声关闭的情况下运行时查看了输出,这就是我发布这个问题的原因。我不明白如何修改替换以使其正常工作。


批量输出错误:

for %%~F in ("%source%") do if not exist "%target%\%~nF.jpg" copy "%%F" "%target%\%~nF.jpg"

The following usage of the path operator in batch-parameter substitution is invalid: %~nF.jpg" copy "%%F" "%target%\%~nF.jpg"


for %%F in ("%source%") do if not exist "%target%\%~nF.jpg" copy "%%~F" "%target%\%~nF.jpg"

The following usage of the path operator in batch-parameter substitution is invalid: %~nF.jpg" copy "%%~F" "%target%\%~nF.jpg"


解决方案:感谢您的协助/解决方案/指导!

set "source=C:\Users\my name\some long path with spaces"
set "target=C:\Users\my name\a 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"

最佳答案

MC ND 快一点,但是你必须只选择源文件中没有扩展名的文件,所以我建议:

@echo off

set source=C:\Users\my name\some long path with spaces
set target=C:\Users\my name\a 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"

关于windows - 批量复制唯一文件到新文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com