Script or batch to copy and rename files

murryc
murryc used Ask the Experts™
on
Need a script or batch to copy a file and rename it, looping X number of times. For instance, I have a file named 180816.SKD. I need to copy that file and rename to 180817.SKD, 180818.SKD, etc. In order to eliminate not having to mess with dates, I could simply start with 180801.SKD and the script could loop through 30 times, naming each copy advancing 01 (180801.SKD) through 31 (180831.SKD).
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT / Software Engineering Consultant
Top Expert 2016
Commented:
Not sure if I completely understand, but this should get you started, adjust as needed.

@echo off
setlocal EnableDelayedExpansion

set CopyFile=180816.SKD
set DestDir=c:\temp

for /l %%i in (1,1,30) do (
    set Day=0%%i
    set Day=!Day:~-2!
    copy "%CopyFile%" "%DestDir%\1808!Day!.SKD"
)

Open in new window

When run this would perform the following copies:

copy "180816.SKD" "c:\temp\180801.SKD"
copy "180816.SKD" "c:\temp\180802.SKD"
copy "180816.SKD" "c:\temp\180803.SKD"
copy "180816.SKD" "c:\temp\180804.SKD"
copy "180816.SKD" "c:\temp\180805.SKD"
copy "180816.SKD" "c:\temp\180806.SKD"
copy "180816.SKD" "c:\temp\180807.SKD"
copy "180816.SKD" "c:\temp\180808.SKD"
copy "180816.SKD" "c:\temp\180809.SKD"
copy "180816.SKD" "c:\temp\180810.SKD"
copy "180816.SKD" "c:\temp\180811.SKD"
copy "180816.SKD" "c:\temp\180812.SKD"
copy "180816.SKD" "c:\temp\180813.SKD"
copy "180816.SKD" "c:\temp\180814.SKD"
copy "180816.SKD" "c:\temp\180815.SKD"
copy "180816.SKD" "c:\temp\180816.SKD"
copy "180816.SKD" "c:\temp\180817.SKD"
copy "180816.SKD" "c:\temp\180818.SKD"
copy "180816.SKD" "c:\temp\180819.SKD"
copy "180816.SKD" "c:\temp\180820.SKD"
copy "180816.SKD" "c:\temp\180821.SKD"
copy "180816.SKD" "c:\temp\180822.SKD"
copy "180816.SKD" "c:\temp\180823.SKD"
copy "180816.SKD" "c:\temp\180824.SKD"
copy "180816.SKD" "c:\temp\180825.SKD"
copy "180816.SKD" "c:\temp\180826.SKD"
copy "180816.SKD" "c:\temp\180827.SKD"
copy "180816.SKD" "c:\temp\180828.SKD"
copy "180816.SKD" "c:\temp\180829.SKD"
copy "180816.SKD" "c:\temp\180830.SKD"

Open in new window


»bp

Author

Commented:
Great work, as always Bill!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial