I'm trying to automate the move of photos from a drop folder into a managed folder, and I'm running the following script.
The problem is, It's not moving any of the files, and I'm not seeing any warnings. I have enabled the -force
option, but it's still not moving anything. Powershell is set up to allow remote execution.
# Preq: Copy all files to $ImportPath`n
$ImportPath = "D:\Photo_Imports"
$JPGDest = "D:\Photos\ALL_PHOTOS\JPG"
$RAWDest = "D:\Photos\ALL_PHOTOS\RAW"
$MOVDest = "D:\Photos\ALL_PHOTOS\Movies"
Write-Host "About to run the script, hold on!" `n
Write-Host "File summary"
Get-Childitem $ImportPath -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc
# If $Path exists, get a list of all children (files/folders) and move each one to the $Dest folders
if(Test-Path $ImportPath)
{
try
{
Get-ChildItem -Path $ImportPath -Include *.JPG -Verbose | Move-Item -Destination $JPGDest -Force
Get-ChildItem -Path $ImportPath -Include *.CR2 -Verbose | Move-Item -Destination $RAWDest -Force
Get-ChildItem -Path $ImportPath -Include *.MOV -Verbose | Move-Item -Destination $MOVDest -Force
}
catch
{
"Something broke, try manually"
}
}
Write-Host `n
Write-Host " FINISHED ! " `n
As stated in the documentation, the -Include parameter works only when the -Recurse is also specified.
So you need to add the -Recurse parameter, like so :
Get-ChildItem -Path $ImportPath -Include *.JPG -Recurse -Verbose | Move-Item -Destination $JPGDest -Force
Get-ChildItem -Path $ImportPath -Include *.CR2 -Recurse -Verbose | Move-Item -Destination $RAWDest -Force
Get-ChildItem -Path $ImportPath -Include *.MOV -Recurse -Verbose | Move-Item -Destination $MOVDest -Force
Or, in case you don't want a recursive file search, don't use -Recurse and replace -Include with -Filter, like so :
Get-ChildItem -Path $ImportPath -Filter "*.JPG" -Verbose | Move-Item -Destination $JPGDest -Force
Get-ChildItem -Path $ImportPath -Filter "*.CR2" -Verbose | Move-Item -Destination $RAWDest -Force
Get-ChildItem -Path $ImportPath -Filter "*.MOV" -Verbose | Move-Item -Destination $MOVDest -Force
For non-recursive search, you could also do this :
Get-ChildItem -Path $ImportPath\*.JPG -Verbose
Get-ChildItem -Path $ImportPath\*.CR2 -Verbose
Get-ChildItem -Path $ImportPath\*.MOV -Verbose