HI誰もが私のPowerShellの練習用のスクリプトを書いて、ユーザの入力に基づいてあるフォルダから別のフォルダにファイルを移動しようとしています。スクリプトは正常に動作しますが、そのファイルがスクリプトと同じフォルダに存在する場合に限ります。誰かが私が間違っているの何私を助けるか、ロジックpowershellのユーザ入力に基づいて別のフォルダにファイルを移動する方法
あなたは、ファイルが現在の場所に存在しているかどうかそうでない場合は、テスト・パスのチェックを完全なファイルパスを決定する必要が$destination = 'P:\Powershell practice\Movefolder'
$ListFile = "P:\Powershell practice\"
get-childitem $ListFile
$Filename = Read-host -prompt "Please Enter File to be moved"
$FileExists = test-path $Filename
If ($FileExists -eq $True) {
move-item $Filename $destination
Write-Host "File is moved to $destination "
}
else
{write-host "No File Found"}
最初は、移動するファイルの正確な名前を入力できるように、PowerShellの練習フォルダのすべてのコンテンツをリストします。問題は、私がスクリプトを実行しているファイルを探しているだけです。ユーザーが入力したファイル名の$ listfileの下を見て、それを移動してください。 – sanees