I have a lot of files with same name but different extensions in different folders (usually .jpg, .crw and .xmp). Files with appropriate metadata have been moved to their own folders, but especially raw files have stayed in the root folder (or upper folders).
Current situation:
C:\Source\Pictures\
FileOne.CRW
FileTwo.CRW
FileXXX.CRW
C:\Source\Pictures\Metadata\
FileOne.XMP
FileOne.JPG
FileTwo.XMP
What I'm looking for:
C:\Source\Pictures\
FileXXX.CRW
C:\Source\Pictures\Metadata\
FileOne.XMP
FileOne.CRW
FileOne.JPG
FileTwo.XMP
FileTwo.CRW
It would be best if raw files (.CRW, .CR2) are moved to the folder where corresponding .xmp/.jpg/.tif files are located, but it would be also sufficient if all corresponding files are moved to one folder.
I've tried the following, but it only works with two file types. And it moves all files to one destination folder. I am fairly okay with this, but it would be better if it could handle more extensions, and move raw files to the folders where .XMP (or .JPG/.TIF) files are.
## INPUT DETAILS
$source_Path = Read-Host -Prompt 'Enter source path'
$dest_Path = Read-Host -Prompt 'Enter destination path'
$ext_GetName = Read-Host -Prompt 'Enter extension name of RAW file (default: ARW)'
if(-not($ext_GetName)){
$ext_GetName = 'ARW'
}
elseif($ext_GetName.Length -ge 4){
Write-output "Extension name is not compatible, make sure you are typing the input max of 3 characters only."
$ext_GetName = Read-Host -Prompt 'Enter extension name of RAW file (default: ARW)'
}
$ext_FindName = Read-Host -Prompt 'Enter extension name of compressed pictures (default: JPG)'
if(-not($ext_FindName)){
$ext_FindName = 'JPG'
}
elseif($ext_FindName.Length -ge 4){
Write-output "Extension name is not compatible, make sure you are typing the input max of 3 characters only."
$ext_FindName = Read-Host -Prompt 'Enter extension name of compressed pictures (default: JPG)'
}
## IF YOU WANT TO USE STATIC DETAILS
## -------------------#
## EXTENSION NAMES
#$ext_GetName = "CR2"
#$ext_FindName = "JPG"
## PATH
#$source_Path = "F:\Pictures\FAMILY, LOVE, FRIENDS, TRAVEL PHOTOS\_Photo Archives\2022-11-28 (AYALA LIGHTS)"
#$dest_Path = "c:\temp\test"
## -------------------#
$ext_GetName_incl = "*."+$ext_GetName
$ext_FindName_incl = "*."+$ext_FindName
$RAWfiles = Get-ChildItem -Path $source_Path -Include $ext_GetName_incl -Recurse -Force -ErrorAction SilentlyContinue
$COMPfiles = Get-ChildItem -Path $source_Path -Include $ext_FindName_incl -Recurse -Force -ErrorAction SilentlyContinue
write-host "Looking for "$ext_GetName" files for chosen "$ext_FindName" files in "$source_Path
##FOR TESTING## Get-ChildItem -Path $source_Path -Include $ext_xxxxx_xxx -Recurse -Force -ErrorAction SilentlyContinue
$counter=0
foreach( $RAWfile in $RAWfiles )
{
foreach( $COMPfile in $COMPfiles )
{
if(($RAWfile.BaseName -eq $COMPfile.BaseName))
{
write-host Successfully copied $RAWfile.name
Move-Item $RAWfile.fullname $dest_Path
Move-Item $COMPfile.fullname $dest_Path
$counter++
}
}
}
write-host Successfully copied $counter files to $dest_Path
pause
Any help would be appreciated!
filename.*