我有一个过程,其中包含数据的文件是在单独的位置生成,保存到网络位置并合并到一个文件中的过程。
在过程的结束时,我想检查该合并文件中是否存在所有位置,并通知我。
我遇到了一个问题,可以找到一种方法来识别不存在特定于每个位置的字符串,即在if语句中使用,但似乎无法正确识别字符串?
我已经尝试过:
get-childitem -filter *daily.csv.ready \\x.x.x.x\data\* -recurse | where-object {$_ -notin 'D,KPI,KPI,1,'}
我知道如果存在的话,什么都不做可能更容易,如果没有,请执行警告措施,但是我很好奇是否可以在反面中完成此操作。
谢谢你,
I have a process where files containing data are generated in separate locations, saved to a networked location, and merged into a single file.
And the end of the process, I would like to check that all locations are present in that merged file, and notify me if not.
I am having a problem finding a way to identify that a string specific to each location isn't present, to be used in an if statement, but it doesn't seem to be identifying the string correctly?
I have tried :
get-childitem -filter *daily.csv.ready \\x.x.x.x\data\* -recurse | where-object {$_ -notin 'D,KPI,KPI,1,'}
I know it's probably easier to do nothing if it is present, and perform the warning action if not, but I'm curious if this can be done in the reverse.
Thank you,
发布评论
评论(1)
AS doug Maurer 指出,您的命令确实 not 通过 content搜索
get-childitem
get-childitem 因为那个cmdlet发出的是system.io.fileinfo
(或者,可能,
system.io.directoryInfo
)包含有关匹配文件(目录)而不是其的实例内容。
换句话说: $ _ 变量在您的
where-object where-object
到对象描述的文件而不是其内容。但是,您 can pipe
system.io.fileinfo
实例select-string
cmdlet,确实搜索输入文件' content :As Doug Maurer points out, your command does not search through the content of the files output by the
Get-ChildItem
command, because what that cmdlet emits areSystem.IO.FileInfo
(or, potentially,System.IO.DirectoryInfo
) instances containing metadata about the matching files (directories) rather than their content.In other words: the automatic
$_
variable in yourWhere-Object
command refers to an object describing a file rather than its content.However, you can pipe
System.IO.FileInfo
instances to theSelect-String
cmdlet, which indeed searches the input files' content: