WSH(・∀・)スレッド! Part 2

このエントリーをはてなブックマークに追加
227デフォルトの名無しさん
// fc.js - 中身が同じファイルを見つける
var CapicomUtil = new ActiveXObject("CAPICOM.Utilities");
// ↑http://www.microsoft.com/downloads/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&DisplayLang=ja
var Fso = new ActiveXObject("Scripting.FileSystemObject");
var Stream1 = new ActiveXObject("ADODB.Stream");
var Stream2 = new ActiveXObject("ADODB.Stream");
var StreamType = {Binary: 1, Text: 2};
var ReadSize = 64;
Stream1.Type = Stream2.Type = StreamType.Binary;
function CompareFiles(file1, file2) {
  Stream1.Open();
  Stream2.Open();
  Stream1.LoadFromFile(file1);
  Stream2.LoadFromFile(file2);
  var rc = true;
  while (! Stream1.EOS) {
    if (CapicomUtil.BinaryToHex(Stream1.Read(ReadSize))
        != CapicomUtil.BinaryToHex(Stream2.Read(ReadSize))) {
      rc = false;
      break;
    }
  }
  Stream1.Close();
  Stream2.Close();
  return rc;
}
/* つづく...
228デフォルトの名無しさん:2007/10/23(火) 21:31:31
...つづき */
function GetFileLists(folder) {
  var lists = {};
  for (files = new Enumerator(Fso.GetFolder(folder).files); ! files.atEnd(); files.moveNext()) {
    var file = files.item();
    var size = file.Size;
    if (! (size in lists))
      lists[size] = [];
    lists[size].push(file.Name);
  }
  return lists;
}
function CompareFileList(folder, list) {
  var len = list.length;
  folder += "\\";
  for (var i = 0; i < len; i++)
    for (var j = i + 1; j < len; j++)
      if (CompareFiles(folder + list[i], folder + list[j]))
        WScript.Echo(list[i] + " == " + list[j]);
}

var folder = ".";
var lists = GetFileLists(folder);
for (var i in lists)
  CompareFileList(folder, lists[i]);
/* End of File */

関数名等が変ですが(^ω^;)