我有一個腳本(粘貼以下)這是應該做到以下幾點:匹配定義的模式是 PowerShell的布展項目 - 不移動文件
- 循環並抓住所有文件位置
- 原始的源文件移動到另一個位置(如果複製成功)
它做的步驟#1和#2,但步驟#3,布展項目是不動的任何文件,我不知道爲什麼,我沒有得到ind錯誤代碼
有人可以幫忙嗎?謝謝
$source = "C:\Users\Tom\"
$source_move = "C:\Users\Tom\OldLogBackup1\"
$destination ="C:\Users\Tom\Mirror\"
if(-not(Test-Path $destination)){mkdir $destination | out-null}
ForEach ($sourcefile In $(Get-ChildItem $source | Where-Object { $_.Name -match "Daily_Reviews\[\d\d\d\d-\d\d\d\d\].journal" }))
{
#escape filename because there are brackets in the name!
$src = [Management.Automation.WildcardPattern]::Escape($sourcefile)
Copy-Item $src $destination
### Check for a successful file copy
if($?)
{
####
if(-not(Test-Path $source_move)){
echo "Path does not exist!"
} else {
echo "Path exists!"
### Move original source file someplace else
Move-Item $source_move$sourcefile $source_move
if($?)
{
echo "Source file successfully moved"
} else {
echo "Source file was not successfully moved"
}
}
}