我有一个脚本(粘贴在下面)应该执行以下操作:
- 循环并抓取与定义的模式匹配的所有文件
- 将这些文件复制到另一个位置
- 将原始源文件移动到另一个位置(如果复制成功)
它正在执行第 1 步和第 2 步,但第 3 步,Move-Item 没有移动任何文件,我不知道为什么,也没有任何错误迹象
有人可以帮忙吗?谢谢
$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"
}
}
}