【发布时间】:2014-09-02 07:14:54
【问题描述】:
大家好,我在搜索和生成文件的哈希值时遇到了问题。我面临的问题是在编写其输出时 到 Out.txt 文件中。我想写两个文件 Data1.txt 和 SqlData.txt 的输出结果,但不幸的是它会擦除第一个文件输出并保存最后一个文件输出结果,即 SqlData.txt 值下面是用于理解代码的简短代码描述
#File1.txt 文件包含我要搜索的两个文件 Data1.txt 和 SqlData.txt 的列表 #Dir1.txt 文件包含我要在其中搜索 $arr 输出文件的目录 (C:) 路径
到目前为止我尝试过的代码。
cls
$arr = Get-ChildItem -Path "C:\Direct\File1.txt"
$d = Get-Content $arr
Foreach ($objFile in $d) {
$c = $objFile.Name
$a = Get-Content "C:\Direct\Dir1.txt"
$e = Get-ChildItem -Path $a -Filter $objFile -Recurse -Force -ErrorVariable FailedItems -ErrorAction SilentlyContinue # Searching the Files
$k = Get-Hash $e > C:\Direct\Reverse\Out.txt #Fetching the Hash value of files and writing output into Out.txt file
}
如果有什么不清楚的地方请告诉我,并帮助我解决这个问题。 谢谢
【问题讨论】:
-
你可以使用管道而不是使用
>。Get-Hash e$ | Out-file C:\Direct\Reverse\Out.txt -AppendAppend 应该阻止它覆盖它已经存在的内容。 -
@Matt yes File1.txt 包含文件名列表而不是完整文件路径
-
所以您正在 C: 驱动器中搜索文件
Data1.txt和SqlData.txt并将这两个文件的哈希输出到out.txt? -
是的,包括文件名和路径
标签: powershell