Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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

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
Regex 使用Powershell复制包含特定关键字的文件,并将其移动到另一个文件夹_Regex_Powershell - Fatal编程技术网

Regex 使用Powershell复制包含特定关键字的文件,并将其移动到另一个文件夹

Regex 使用Powershell复制包含特定关键字的文件,并将其移动到另一个文件夹,regex,powershell,Regex,Powershell,我将匹配我要查找的特定文本的文件路径存储在名为$FilePath的变量中。现在,我要做的是复制那些与我要查找的内容匹配的文件,并将它们放入一个新文件夹中,比如说,文件路径:C:\newfolder 我编写了以下简单脚本,但两种脚本都不起作用: 一, 二, 我使用$filepaths=$files | format table*-wrap将文件路径转换为表格格式(有效)-但这可能就是问题的原因 我在这里哪里出错了?啊哈格式-…问题 如果要再次使用数据,请不要使用格式化任何内容。通过保存表格格式,您

我将匹配我要查找的特定文本的文件路径存储在名为$FilePath的变量中。现在,我要做的是复制那些与我要查找的内容匹配的文件,并将它们放入一个新文件夹中,比如说,文件路径:C:\newfolder

我编写了以下简单脚本,但两种脚本都不起作用:

一,

二,


我使用
$filepaths=$files | format table*-wrap将文件路径转换为表格格式(有效)-但这可能就是问题的原因


我在这里哪里出错了?

啊哈
格式-…
问题

如果要再次使用数据,请不要使用
格式化任何内容。通过保存表格格式,您已损坏了所拥有的对象

我不知道
$files
是什么,但是如果它是从
Get ChildItem
输出的,那么就不需要了,你会没事的。如果它只是一个字符串数组,情况也是如此

看看下面的例子

适当输出
Get ChildItem c:\temp | Get Member
将为您提供
System.IO.DirectoryInfo
System.IO.FileInfo
对象的潜在组合

“损坏”输出
Get ChildItem c:\temp | Format Table | Get Member
将为您提供如下对象。不止这些,关键是原始对象已经消失了

Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
 ....

它们都应该在第一个变更中使用一个变更<代码>复制项目-路径$filepath-目标C:\newfolder
。你没有收到任何错误吗?您确定
$filepath
包含它应该包含的数据,并且它不是空的吗?我将文件路径转换为表格格式,即使用$filepath=$files | format table*-wrap[哪一种有效]——但这可能是导致问题的原因?如果是,文件路径的最佳格式是什么?
foreach($match in $filepaths)
{
    Copy-Item -path $match -Destination C:\newfolder
}
Microsoft.PowerShell.Commands.Internal.Format.GroupStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
 ....