Move a copy of unknown named images and rename - Powershell or Batch Script
Solution 1:
How can I copy 10 files to a new directory and rename them with a pattern?
Use the following batch file (test.cmd):
@echo off
setlocal EnableDelayedExpansion
set "source_dir=f:\test\jpg"
set "target_dir=f:\test\target"
for /f "tokens=*" %%f in ('dir /b %source_dir%\*.jpg') do (
set /a "count+=1"
set /a "target_count=!count!+100"
copy "%source_dir%\%%f" "!target_dir!\e!target_count!.jpg" > nul
if !count! EQU 10 goto :done
)
rem finished
:done
endlocal
Notes:
- Change
source_dir
andtarget_dir
as appropriate
Example:
> dir jpg
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test\jpg
12/03/2019 11:39 <DIR> .
12/03/2019 11:39 <DIR> ..
12/03/2019 11:34 4,429 Test_image (01).jpg
12/03/2019 11:34 4,429 Test_image (02).jpg
12/03/2019 11:34 4,429 Test_image (03).jpg
12/03/2019 11:34 4,429 Test_image (04).jpg
12/03/2019 11:34 4,429 Test_image (05).jpg
12/03/2019 11:34 4,429 Test_image (06).jpg
12/03/2019 11:34 4,429 Test_image (07).jpg
12/03/2019 11:34 4,429 Test_image (08).jpg
12/03/2019 11:34 4,429 Test_image (09).jpg
12/03/2019 11:34 4,429 Test_image (10).jpg
12/03/2019 11:34 4,429 Test_image (11).jpg
12/03/2019 11:34 4,429 Test_image (12).jpg
12/03/2019 11:34 4,429 Test_image (13).jpg
12/03/2019 11:34 4,429 Test_image (14).jpg
12/03/2019 11:34 4,429 Test_image (15).jpg
12/03/2019 11:34 4,429 Test_image (16).jpg
16 File(s) 70,864 bytes
2 Dir(s) 1,005,493,501,952 bytes free
> test
> dir target
Volume in drive F is Expansion
Volume Serial Number is 3656-BB63
Directory of F:\test\target
12/03/2019 12:07 <DIR> .
12/03/2019 12:07 <DIR> ..
12/03/2019 11:34 4,429 e101.jpg
12/03/2019 11:34 4,429 e102.jpg
12/03/2019 11:34 4,429 e103.jpg
12/03/2019 11:34 4,429 e104.jpg
12/03/2019 11:34 4,429 e105.jpg
12/03/2019 11:34 4,429 e106.jpg
12/03/2019 11:34 4,429 e107.jpg
12/03/2019 11:34 4,429 e108.jpg
12/03/2019 11:34 4,429 e109.jpg
12/03/2019 11:34 4,429 e110.jpg
10 File(s) 44,290 bytes
2 Dir(s) 1,005,493,379,072 bytes free
Further Reading
- An A-Z Index of the Windows CMD command line | SS64.com
- Windows CMD Commands (categorized) - Windows CMD - SS64.com
- Copy files - Windows CMD - SS64.com
- Dir - list files and folders - Windows CMD - SS64.com
- EnableDelayedExpansion - Windows CMD - SS64.com
- For - Loop through command output - Windows CMD - SS64.com