本帖最后由 WHY 于 2018-2-1 13:33 编辑
test.js- var srcDir1 = 'D:/01';
- var srcDir2 = 'D:/02';
- var dstDir = 'D:/03';
-
- var totalNum = 0;
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var e = new Enumerator(fso.GetFolder(srcDir1).files);
-
- if(!fso.FolderExists(dstDir)) fso.CreateFolder(dstDir);
-
- for(; !e.atEnd(); e.moveNext()){
- var srcFile1 = e.item().Path;
- var srcFile2 = srcDir2 + '/' + e.item().Name;
-
- if(/\.txt$/i.test(srcFile1) && fso.FileExists(srcFile2)){
- totalNum += IsContained(srcFile1, srcFile2);
- }
- }
-
- function IsContained(srcFile1, srcFile2){
- var str1 = fso.OpenTextFile(srcFile1, 1).ReadAll();
- var str2 = fso.OpenTextFile(srcFile2, 1).ReadLine();
-
- var reg = new RegExp('^' + str2 + '$', 'mi');
- if(reg.test(str1)) { return 1; } else return 0;
- }
-
- fso.OpenTextFile(dstDir + '/统计.txt', 2, true).WriteLine(totalNum);
-
- WSH.Echo('Done!')
复制代码
|