将输出从 get-childitem 传送到 robocopy
我有一组文件需要移动到备份位置。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Robocopy 需要源目录、目标目录和文件规范作为参数。如果不知道你的“收集物品列表”是什么样子,就很难给出明确的答案。如果它是源目录,那么您可以通过调用 robocopy 来查找该列表,并对文件名的通配符规范进行硬编码。如果您有文件列表,则需要将它们拆分为目录/文件(我使用 split-path),并为每个源目录调用 robocopy,指定该目录中的文件列表目录。
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.
类似的情况,发布以防万一有帮助:
我需要复制(移动)一些以“星期五”开头的文件夹以及从源到目的地的项目,并想出了这个似乎有效的方法:
与“星期五”(-过滤器“星期五*”)。
我对 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:
with "Friday" (-Filter "Friday*").
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).
对我有用的语法:(
根据 robocopy 文档,这是显而易见的)
Syntax that worked for me:
(which is obvious according to the robocopy documentation)
robocopy
robocopy