Computing Staff
  • 2

Xcopy With Folder Rename If Exist

  • 2

I want to make a batch file to copy a directory to another folder, using “xcopy”, but I want the batch file to check first if the destination directory already exists, then to rename the new copied directory by appending 1 to it and so on subsequently.

Share

1 Answer

  1. :: I’ll leave it to you to nuke out the xcopy bit.
    ::
    ::
    ::
    ::====== script starts here ===============
    :: sequential backup folder numbers
    :: SEQ!back.bat 2014-07-16 21:17:36.77
    @echo off & setLocal enableDELAYedeXpansioN
    for /L %%a in (1 1 1000) do (
    if not exist d:\bak\mypix%%a (
    set DEST=d:\bak\mypix%%a
    goto :done
    )
    )
    :done
    echo.DEST is !DEST!
    goto :eof
    ::====== script ends here =================

    • 0