我在 powershell 中定义了一个哈希表,如下所示:
$jobs = @{
"Test1"=[Array](
[Array]("\\server1\file1.txt", "\\server2\file1.txt")
);
"Test2"=[Array](
[Array]("\\sever1\file2.txt", "\\server2\file2.txt"),
[Array]("\\server1\file3.txt", "\\server2\file3.txt")
);
}
我试图枚举这个集合并在每一对上调用一个函数。Test1 有 1 个文件比较,Test2 有两个文件比较。
$jobs.GetEnumerator() | Sort-Object Key | foreach {
LogWrite($_.Key + ": comparing files")
$_.value | foreach {
LogWrite("Comparing files '" + $_[0] + "' and '" + $_[1] + "'")
#$r = CompareFiles($_[0], $_[1])
#LogWrite("Result : " + $r)
}
LogWrite($_.Key + ": comparison successful")
LogWrite("")
}
我得到的输出是:
Test1: comparing files
Comparing files '\' and '\'
Comparing files '\' and '\'
Test1: comparison successful
Test2: comparing files
Comparing files '\\server1\file2.txt' and '\\server2\file2.txt'
Comparing files '\\server1\file3.txt' and '\\server2\file3.txt'
Test2: comparison successful
Powershell(某物)似乎正在创建大小相等的数组。任何人都可以提出更好的数据结构或解决方案吗?