- Copy first ten jpg files in folder in alphanumerical order to new folder with out prior knowledge of jpg file names.
- Give each ten files in new location specific names like 'e100.jpg' – 'e110.jpg'.
- Powershell or batch script solution to run in windows enviroment.
Current research across related stack exchange posts:
-
SO – Copy first N files from source directory to “serialized” destination directory using powershell
-
SO – Powershell to pick random files from a folder and move them to another folder
-
Bulk renaming of files in PowerShell with sequential numeric suffixes
If I were to guess at a solution, based on the research as my coding skill are not very good, I think one of the solutions would look something like this:
Powershell
$excludealreadycopieditems = @()
$sourcefolder = "C:\SYS1"
$destinationFolder = "C:\SYS2"
$maxitems = 10
#Calculate how many folders should be created:
$folderstocreate = [math]::Ceiling((get-childitem $sourcefolder\*.jpg).count / $maxitems)
#Copy the items (if moving in stead of copy use Move-Item)
get-childitem $sourcefolder\*.jpg -Exclude $excludealreadycopieditems | sort-object name | select -First $maxitems | Copy-Item -Destination $destinationFolder$i ;
#Exclude the already copied items:
$excludealreadycopieditems = $excludealreadycopieditems + (get-childitem $destinationFolder$i\*.jpg | select -ExpandProperty name)
}
ls *jpg | Foreach {$i=1} {Rename-Item _ -NewName ("$($.100){$:110#} .jpg" -f $i++) -whatif}
CMD
@ECHO OFF
SET SrcCount=0
SET SrcMax=10
FOR %F IN (C:\SYS1\*.jpg) DO IF !SrcCount! LSS %SrcMax% (
SET /A SrcCount += 1
ECHO !SrcCount! COPY %F C:\SYS2
COPY %F C:\temp\output
)
ren *.jpg e100.* e103.* e104.* e105.* e106.* e107.* e108.* e109.* e110.*
Best Answer
How can I copy 10 files to a new directory and rename them with a pattern?
Use the following batch file (test.cmd):
Notes:
source_dir
andtarget_dir
as appropriateExample:
Further Reading