$TargetPath = "E:\Pictures"
$SourcePath = "$($env:USERPROFILE)"
$Pictures = Get-ChildItem -Path $SourcePath -Recurse -Include "*.jpg","*.jpeg","*.bmp","*.gif","*.png"
If(-not(Test-Path $TargetPath))
{
New-Item -Path $TargetPath -ItemType Directory
}
foreach ($Picture in $Pictures)
{
$NewPicturePath = $null
$DestinationDirectory = Get-ChildItem -Path $TargetPath
$PictureExists = $false
foreach($CopiedPicture in $DestinationDirectory)
{
If($Picture.Name -eq $CopiedPicture.Name)
{
$WriteTime = ".$($Picture.LastWriteTime.ToString("yyyy-mm-dd"))"
$extensionIndex = $Picture.Name.LastIndexOf('.')
$NewPictureName = $Picture.Name.Insert($extensionIndex,$WriteTime)
$NewPicturePath = "$TargetPath\$NewPictureName"
Copy-Item -LiteralPath $Picture.FullName -Destination $NewPicturePath -Force
$PictureExists = $true
break
}
}
If(-not($PictureExists))
{
Copy-Item -LiteralPath $Picture.FullName -Destination $TargetPath -Force
}
}