0

I already found a solution for this but what I need now is to find shortest line of command. Situation : File "C:\Image.jpg" move to "D:\". If "Image.jpg" exist in "D:\" then rename and move it as "Image01.jpg". This command looping. Here my batch command line :

:start
IF EXIST "D:\Users\00002829\Pictures\Image.jpg" IF EXIST "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image03.jpg" (
    move "D:\Users\00002829\Pictures\Image.jpg" "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image04.jpg"
)
IF EXIST "D:\Users\00002829\Pictures\Image.jpg" IF EXIST "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image02.jpg" (
    move "D:\Users\00002829\Pictures\Image.jpg" "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image03.jpg"
)
IF EXIST "D:\Users\00002829\Pictures\Image.jpg" IF EXIST "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image01.jpg" (
    move "D:\Users\00002829\Pictures\Image.jpg" "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image02.jpg"
)
IF EXIST "D:\Users\00002829\Pictures\Image.jpg" (
    move "D:\Users\00002829\Pictures\Image.jpg" "D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray\Image01.jpg"
)
TIMEOUT /t 3
goto start

This command only limited to 3 times file rename and move. Thx

Falhuddin
  • 103
  • 2
  • 11
  • Possible duplicate of [How to Copy (and increment) Multiple Instances of a File Using Batch File](https://stackoverflow.com/questions/28697436/how-to-copy-and-increment-multiple-instances-of-a-file-using-batch-file) –  Nov 23 '18 at 10:50

1 Answers1

0

Just loop it and find all the files, copy them and rename if exist.

@echo off
setlocal disableDelayedExpansion
set "source=D:\Users\00002829\Pictures"
set "target=D:\Users\00002829\Pictures\SFSAPP\VChip_X-Ray"

md "%target%"
set /a cnt=0
for /r %%F %target% in (Image.jpg) do if "%%~dpF" neq "%target%\" (
  if exist "%%F" (
  if exist "%target%\%%~nxF" (
    set /a cnt+=1
    set "full=%%F"
    set "name=%%~nF"
    set "ext=%%~xF"
    setlocal enableDelayedExpansion
    copy "!full!" "!target!\!name!!cnt!!ext!" >nul
    endlocal
  ) else copy "%%F" "%target%" >nul
 )
)
Gerhard
  • 22,678
  • 7
  • 27
  • 43