将输出从 get-childitem 传送到 robocopy

发布于 2024-10-17 21:30:13 字数 270 浏览 2 评论 0原文

我有一组文件需要移动到备份位置。我正在使用 get-childitem 命令收集所需项目的数组。我希望在收集的物品列表准备好后使用 robocopy 来移动物品。

$paths=@()

$srcitems = get-childitem $paths 

robocopy $srcitems $dest /move

这有效吗?
如果不是,将每个单独的项目通过管道传送到 robocopy 的最佳方法是什么?

谢谢
钢铁用户

I have an array of files that need to be moved to a backup locations. I am collecting the array of desired items using a get-childitem command. I am looking to use robocopy to move stuff once the list of collected items is ready.

$paths=@()

$srcitems = get-childitem $paths 

robocopy $srcitems $dest /move

Does this work?
If not what is the best way to pipe to each individual item to robocopy?

Thanks
Steeluser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

战皆罪 2024-10-24 21:30:13
           Usage :: ROBOCOPY source destination [file [file]...] [options]

         source :: Source Directory (drive:\path or \\server\share\path).
    destination :: Destination Dir  (drive:\path or \\server\share\path).
           file :: File(s) to copy  (names/wildcards: default is "*.*").

Robocopy 需要源目录、目标目录和文件规范作为参数。如果不知道你的“收集物品列表”是什么样子,就很难给出明确的答案。如果它是源目录,那么您可以通过调用 robocopy 来查找该列表,并对文件名的通配符规范进行硬编码。如果您有文件列表,则需要将它们拆分为目录/文件(我使用 split-path),并为每个源目录调用 robocopy,指定该目录中的文件列表目录。

           Usage :: ROBOCOPY source destination [file [file]...] [options]

         source :: Source Directory (drive:\path or \\server\share\path).
    destination :: Destination Dir  (drive:\path or \\server\share\path).
           file :: File(s) to copy  (names/wildcards: default is "*.*").

Robocopy is expecting a source directory, a destination directory, and a file spec as arguments. It's difficult to give a definitive answer without knowing what your "list of collected items" looks like. If it's source directories, then you can foreach that list through a an ivocation of robocopy, and hardcode a wildcard spec for the file names. If you've got a list of files, you'll need to split those off into directory/file (I'd use split-path), and do an invocation of robocopy for each source directory, specifying the list of files in that directory.

为你拒绝所有暧昧 2024-10-24 21:30:13

类似的情况,发布以防万一有帮助:

我需要复制(移动)一些以“星期五”开头的文件夹以及从源到目的地的项目,并想出了这个似乎有效的方法:

Get-ChildItem T:\ParentFolder -Filter "Friday*" -Name | ForEach-Object { robocopy "T:\ParentFolder\$_" "E:\$_" /z /s /MOVE }
  • “Get-ChildItem” " 部分列出了以 (-Name) 开头的文件夹名称
    与“星期五”(-过滤器“星期五*”)。
  • 这将通过管道传输到 ForEach-Object,其中 robocopy 将为找到的每个实例执行。
  • robocopy /MOVE 参数显然会移动文件夹/文件。

我对 Powershell 相当陌生;不确定是否有更好的方法。该脚本仍在运行,但到目前为止一切顺利。

@walid2mi 使用 Move-Item,我确信它可以工作;我只是喜欢 robocopy b/c 它有一个可重新启动模式 (/Z)。

Similar scenario, posting in case it helps:

I needed to copy (move) some folders all beginning with "Friday" and items within from a source to a destination, and came up with this that seems to be working:

Get-ChildItem T:\ParentFolder -Filter "Friday*" -Name | ForEach-Object { robocopy "T:\ParentFolder\$_" "E:\$_" /z /s /MOVE }
  • The "Get-ChildItem" portion lists the folder names (-Name) starting
    with "Friday" (-Filter "Friday*").
  • This gets piped to the ForEach-Object where robocopy will execute for every instance found.
  • The robocopy /MOVE argument obviously moves the folders/files.

I'm fairly new to Powershell; not sure if there is a better way. The script is still running, but so far so good.

@walid2mi uses Move-Item which I'm sure works; I just like robocopy b/c it has a restartable mode (/Z).

烧了回忆取暖 2024-10-24 21:30:13

对我有用的语法:(

$srcPath = "C:\somefolder"
$dstPath = "C:\someOtherFolder"
$srcitems = get-childitem $srcPath #whatever condition

$srcitems | Select Name | ForEach-Object {robocopy $srcPath $dstPath $_.name}

根据 robocopy 文档,这是显而易见的)

Syntax that worked for me:

$srcPath = "C:\somefolder"
$dstPath = "C:\someOtherFolder"
$srcitems = get-childitem $srcPath #whatever condition

$srcitems | Select Name | ForEach-Object {robocopy $srcPath $dstPath $_.name}

(which is obvious according to the robocopy documentation)

我是有多爱你 2024-10-24 21:30:13

robocopy

Get-ChildItem $paths | Move-Item -Destination $dest  -WhatIf

robocopy

Get-ChildItem $paths | Move-Item -Destination $dest  -WhatIf
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文