2016-06-25 55 views
0

ドロップフォルダから管理フォルダに写真を移動するのを自動化しようとしていますが、次のスクリプトを実行しています。PowerShell Move-Itemがファイルの移動に失敗しました

問題は、ファイルを移動していないため、警告が表示されないということです。私は-forceオプションを有効にしましたが、それでも何も動かされていません。 Powershellはリモート実行を可能にするように設定されています。

# 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 

答えて

0

としては、-Includeパラメータが-Recurseも指定されている場合のみ動作しますが、in the documentationを述べました。

だから、あなたがそうのように、-Recurseパラメータを追加する必要があります。

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 

あるいは、場合にあなたが-Recurseを使用し、交換しない、再帰的なファイル検索をしたくありませんそのような -Filter -Include、非再帰的な検索のために

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 

、あなたのCこれもやってください:

Get-ChildItem -Path $ImportPath\*.JPG -Verbose 
Get-ChildItem -Path $ImportPath\*.CR2 -Verbose 
Get-ChildItem -Path $ImportPath\*.MOV -Verbose 
関連する問題