在目录中移动文件夹

时间:2019-03-16 18:27:59

标签: powershell

我正在尝试制作一个Powershell脚本,该脚本允许我使用过滤器从目录中移走所有文件夹以排除某些内容。但是问题在于,当尝试移动文件夹时,其中的内容将被移动,并且文件夹将被删除,而不是整个文件夹都在移动。

脚本

[string] $currentDir = $PSScriptRoot
[string] $newDir = $currentDir + '\moveFolder'

# I have tried both of these but the result is still the same
Get-ChildItem -Path $currentDir -Directory | Where-Object { $_.FullName -notmatch 'moveFolder'} | Move-Item -Destination ($newDir + '\build')
Move-Item -Path ($currentDir + '\*') -Destination ($newDir + '\build') -Exclude moveFolder

发生的事的例子

之前

- Main Folder
    - Subfolder1
       - abc
       - abcd.txt
    - moveFolder

之后

- Main Folder
   - moveFolder
      - abc
      - abcd.txt

就像您看到文件夹的内容被移动一样,而不是整个文件夹都被移动了。当我在Powershell窗口中尝试时,它可以工作,但是从脚本文件运行时,会发生这种情况。

1 个答案:

答案 0 :(得分:0)

弄清楚了。我忘记创建“构建”文件夹。我创建了“ moveFolder”,但完全忘记了。

最终结果如下

[{"containerType":"Drive","testAtts":"{\"idNbr\":\"11111111111\",\"name\":\"ATTTT\"}"}]
相关问题