0

我有一台运行 Windows Server 2003 R2 Enterprise 的服务器,每个目录包含 50,000 到 250,000 个 1KB 文本文件。文件名是连续的(例如,MLLP000001.rcv、MLLP000002.rcv 等),相同的文件将是连续的。一旦后续文件不同,我可以预期我不会收到另一个相同的文件。

我需要一个脚本来执行以下操作,但我不知道从哪里开始。

for each file in the target directory index 'i'
{
  for each file in the target directory index 'j' = i+1
  {
    compare the hash values of files i and j

    if the hashes are identical
      delete file j
    if the hashes differ
      set i = j // to skip past the files that are now deleted
      break
  }
}

我尝试了 DOS 批处理脚本,但这真的很麻烦,我无法跳出内部循环,并且它会自行绊倒,因为外部循环在目录中有一个文件列表,但该列表不断变化。据我所知,VBScript 没有散列函数。

4

2 回答 2

1

由于文件大小只有 1KB,为什么不进行按位比较并避免散列呢?

于 2011-04-07T09:12:43.620 回答
0

听起来您可以执行以下操作:

Set Files to an array of files in a given directory.
Set PreviousHash to hash of the first file in the Files.

For each CurrentFile file after the first in Files,
    Set CurrentHash to hash of the CurrentFile.
    If CurrentHash is equal to PreviousHash, then delete CurrentFile.
    Else, set PreviousHash to CurrentHash.
于 2011-04-06T20:36:07.557 回答