0

I need batch script to copy all files from one directory to another and rename them all to a default name (ex. NAME54.pdf) and continue counting from destination`s maximum number in name. I wrote some script but it seems not working:

@echo on
D:

set count=0
for %%a in (scans1\*.*) do (
set /a count+=1
)

set count1=0
for %%b in (scans\*.*) do (
set /a count1+=1
)

for /l %%c in (1,1,%count1%) do (
set /a count+=1
copy D:\scans\*.* D:\scans\NAME%count%.pdf
)

pause
djoleasterix
  • 51
  • 1
  • 6

1 Answers1

0
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
SET "destdir=U:\destdir"
SET /a count=0
for %%c in (%sourcedir%\*.*) do (
 CALL :select
 ECHO copy "%%c" "%destdir%\NAME!count!.pdf"
)

GOTO :EOF

:select
SET /a count+=1
IF EXIST "%destdir%\NAME%count%.pdf" GOTO select
GOTO :eof

I've set up distinct source and destination directories. You would need to change these names to suit your circumstances.

I've chosen to simply ECHO the required copy command so that you can see the resultant commands. You'd need to change ECHO copy to copy to actually execute the commands.

If you append >nul to the copy command, the 1 file(s) copied response will be suppressed.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Thans @Magoo this worked well. I have another issue. Anyway, it would be so helpful if you could make it copy only files that have been created on the date the script is to be ran. – djoleasterix Jul 30 '14 at 11:42