fso查找被删除的文件

<html>
<head>
</head>
<body>
源目录:<input id="txtOld" value="F:\开发\fso"></input>
新目录:<input id="txtNew"></input>
对比:<input id="btnCompare" onclick="compareFile()" type="button" value="compare"></input>
<br/>
<textarea id="txtContent" style="width:100%;height:100%"></textarea>
<script>
var subfolder;
var thefile;
var filename;
var FSO = new ActiveXObject("Scripting.FileSystemObject");
//var rootFolder = FSO.getFolder();
var fileArray = [];
var newFileObj = {};
var deleteFileArray = [];
var oldFolderPath = "", newFolderPath = "";

function $(id)
{
return document.getElementById(id);
}

function compareFile()
{
fileArray = [];
deleteFileArray = [];
oldFolderPath = $("txtOld").value;
newFolderPath = $("txtNew").value;
Scan(newFolderPath);
$("txtContent").value = fileArray.join("\r\n");
ScanOldFolder(oldFolderPath );
// alert(fileArray.length);
alert(deleteFileArray.length);
}

function ScanOldFolder(folderName)
{
var folder = FSO.getFolder(folderName);
if (folder.subFolders.count > 0)
{
var fenum = new Enumerator(folder.subFolders);
for (var i = 0 ; !fenum.atEnd(); fenum.moveNext(),i++){
//datas.WriteLine("datas["+ i +"] = \""+ fenum.item().Name +"\";") ;
Scan(fenum.item().path);
}
}
//'下面一段将文件夹中的文件路径显示在LABEL上并刷新窗体
if (folder.Files.count > 0)
{
var fenum = new Enumerator(folder.Files);
for (var i = 0 ; !fenum.atEnd(); fenum.moveNext(),i++){
//datas.WriteLine("datas["+ i +"] = \""+ fenum.item().Name +"\";") ;

var newPath = fenum.item().path.replace(newFolderPath + "\", "");
if (typeof newFileObj[newPath] != "undefined")
{
deleteFileArray.push(newPath);
}
}
}
}

function Scan(folderName)
{
var folder = FSO.getFolder(folderName);
if (folder.subFolders.count > 0)
{
var fenum = new Enumerator(folder.subFolders);
for (var i = 0 ; !fenum.atEnd(); fenum.moveNext(),i++){
//datas.WriteLine("datas["+ i +"] = \""+ fenum.item().Name +"\";") ;
Scan(fenum.item().path);
}
}
//'下面一段将文件夹中的文件路径显示在LABEL上并刷新窗体
if (folder.Files.count > 0)
{
var fenum = new Enumerator(folder.Files);
for (var i = 0 ; !fenum.atEnd(); fenum.moveNext(),i++){
//datas.WriteLine("datas["+ i +"] = \""+ fenum.item().Name +"\";") ;
var oldFile = fenum.item().path.replace(oldFolderPath+"\", "");
fileArray.push(oldFile);
newFileObj[oldFile] = oldFile;
}
}
}
</script>
</body>
</html>

你可能感兴趣的:(文件)