Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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 CMD/Powershell:使用部分路径通配符复制文件_Windows_Powershell_Cmd - Fatal编程技术网

Windows CMD/Powershell:使用部分路径通配符复制文件

Windows CMD/Powershell:使用部分路径通配符复制文件,windows,powershell,cmd,Windows,Powershell,Cmd,我想使用Windows命令提示符、Powershell或两者的组合来实现以下功能: 假设给我们一个源目录,sourcedir和一个目标目录destinationdir,我们希望递归地将文件从源复制到目标 我们还得到了一个通配符过滤器,如so*/foo/bar/*;过滤器意味着在sourcedir中查找路径中任何位置包含/foo/bar/的所有文件。例如,sourcedir/foo/bar/file1.txt和sourcedir/baz/foo/bar/file2.txt将被复制,而sourced

我想使用Windows命令提示符、Powershell或两者的组合来实现以下功能:

假设给我们一个源目录,
sourcedir
和一个目标目录
destinationdir
,我们希望递归地将文件从源复制到目标


我们还得到了一个通配符过滤器,如so
*/foo/bar/*
;过滤器意味着在
sourcedir
中查找路径中任何位置包含
/foo/bar/
的所有文件。例如,
sourcedir/foo/bar/file1.txt
sourcedir/baz/foo/bar/file2.txt
将被复制,而
sourcedir/foo/baz/bar/file3.txt
将不被复制

是的,用一堆随机的东西解决了这个问题。事实证明,
*/foo/bar/*
部分路径在Get ChildItem中有效:

Get ChildItem-Path“$($sourcedir)\$($filter)”-递归|复制项-目标$destinationdir

您可以尝试以下操作

copy-Item $SourceDir $DestinationDir -recurse

选择一种语言,然后思考它可能如何做到这一点,尝试一些事情,然后将你遇到的问题发布到其中一个小组。???这是我在工作中所做的一项任务的一个要求,整个事情都挂在这一步上。我尝试了一些涉及Get-ChildItem和Where-Object的方法,但都没有真正起作用。实际上,问题的根源在于命令提示符或Powershell似乎都不支持常规的
**/
部分路径通配符。我建议您开始使用Powershell或.Net[[System.IO.path]::Combine()()连接文件路径。使用其中一个将确保您构造的路径在语法上是正确的。(您不会错误地“错过”反斜杠)