Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows PowerShell移动项目-不移动文件_Windows_Powershell - Fatal编程技术网

Windows PowerShell移动项目-不移动文件

Windows PowerShell移动项目-不移动文件,windows,powershell,Windows,Powershell,我在下面粘贴了一个脚本,它应该执行以下操作: 循环并获取与定义模式匹配的所有文件 将这些文件复制到其他位置 如果复制成功,请将原始源文件移动到其他位置 它正在执行第1步和第2步,但第3步,Move Item没有移动任何文件,我不知道为什么,也没有发现任何错误迹象 有人能帮忙吗?谢谢 $source = "C:\Users\Tom\" $source_move = "C:\Users\Tom\OldLogBackup1\" $destination ="C:\Users\Tom\Mirror\"

我在下面粘贴了一个脚本,它应该执行以下操作:

循环并获取与定义模式匹配的所有文件 将这些文件复制到其他位置 如果复制成功,请将原始源文件移动到其他位置 它正在执行第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"

    }
  }
}
请尝试使用-force选项。

行移动项$source\u Move$sourcefile$source\u Move正在将$source\u Move目录中的$sourcefile移动到$source\u Move目录,但不执行任何操作。我猜您是想移动项目$source$sourcefile$source\u Move或移动项目$src$source\u Move

此外,echo只是的别名,它将参数返回给调用者。您可以在没有回声的情况下获得相同的结果,任何对象本身都将被返回。或者,如果您打算将它们用作调试语句,则可以使用或