1

我正在尝试通过将 (1) 附加到重复文件之一来移动文件并保留重复的文件名。

我在用着

cd /D "source directory"
move *.JPG "target directory"

这并不能解决问题。有人可以帮忙吗?

感谢您的帮助。

4

1 回答 1

2

这应该做你想要的。我们 dir 并搜索.jpg源文件夹中的所有文件,然后检查它是否存在,如果存在,使用计数器附加一个数字,如果不存在,我们只是移动它..

@echo off
setlocal enabledelayedexpansion
set "source=D:\source\"
set "dest=D:\destination\"
set /a cnt=0
for /f "tokens=*" %%a in ('dir /S /B /A-D "%source%*.jpg"') do for /f "tokens=*" %%b in ('dir /B "%%a"') do if exist "%dest%\%%b" (
        set "ext=%%~xa"
        set "fname=%%~na"
        if exist "%dest%\!fname!(!cnt!)!ext!" (set /a cnt=!cnt!+1)
        set /a cnt=!cnt!+1
        move "%%a" "%dest%\!fname!(!cnt!)!ext!"
) else move "%%a" "%dest%\%%b"
于 2018-09-07T06:38:46.753 回答