ForEach-Object / Copy-Item only内容(不是文件夹本身!)

时间:2018-01-23 20:58:57

标签: powershell copy-item

我有代码查找文件夹,然后查找我告诉它的条件。到现在为止还挺好。然后我得到一个ws:,其中包含ForEach-Object。代码本身正在运行并且没有错误,但我不想复制文件夹本身及其内容。我只是想复制文件夹的内容。我已经尝试了Copy-Item $_.Fullname之类的东西等等。

这是我的代码的样子:

$_.Fullname/*

修改1:

我的文件夹结构如下所示:

M143                       ← (Root Folder)
├─Backups                  ← (Folder, here are Backups stored)
│ ├─Fullbackup...
│ ├─Incrementalbackup...   ← Copy Content of this folder, without folder)
│ └─Differentialbackup...  ← (Into this folder)
└─Backup_Script.ps1

1 个答案:

答案 0 :(得分:0)

这......

Copy-Item -Path $_.FullName -Recurse

...是你的问题。以下应该是你想要的。

(Get-ChildItem -Path E:\BackUps -Recurse).FullName

复制前的结果

E:\BackUps\Differential
E:\BackUps\Full
E:\BackUps\Incremental
E:\BackUps\Incremental\IncBU001.bkp
E:\BackUps\Incremental\IncBU002.bkp
E:\BackUps\Incremental\IncBU003.bkp

Copy-Item -Path 'E:\BackUps\Incremental\*' -Destination 'E:\BackUps\Differential'

(Get-ChildItem -Path E:\BackUps -Recurse).FullName

复制后的结果

E:\BackUps\Differential
E:\BackUps\Full
E:\BackUps\Incremental
E:\BackUps\Differential\IncBU001.bkp
E:\BackUps\Differential\IncBU002.bkp
E:\BackUps\Differential\IncBU003.bkp
E:\BackUps\Incremental\IncBU001.bkp
E:\BackUps\Incremental\IncBU002.bkp
E:\BackUps\Incremental\IncBU003.bkp