[UMU WSH 教程](10)常见对象 - WScript.Shell
FSO 用来操作文件的对象,全名是 Scripting.FileSystemObject。依然是按照《[UMU WSH 教程](9)CreateObject 过程》说的方法,用 eXeScope 打开 C:\WINDOWS\system32\scrrun.dll,查看 TYPELIB,可以看到这个对象有以下接口函数(省略 IDispatch 接口函数):
property-get Drives: ^IDriveCollection;
function BuildPath(Path:BSTR; Name:BSTR): BSTR;
function GetDriveName(Path:BSTR): BSTR;
function GetParentFolderName(Path:BSTR): BSTR;
function GetFileName(Path:BSTR): BSTR;
function GetBaseName(Path:BSTR): BSTR;
function GetExtensionName(Path:BSTR): BSTR;
function GetAbsolutePathName(Path:BSTR): BSTR;
function GetTempName: BSTR;
function DriveExists(DriveSpec:BSTR): bool;
function FileExists(FileSpec:BSTR): bool;
function FolderExists(FolderSpec:BSTR): bool;
function GetDrive(DriveSpec:BSTR): ^IDrive;
function GetFile(FilePath:BSTR): ^IFile;
function GetFolder(FolderPath:BSTR): ^IFolder;
function GetSpecialFolder(SpecialFolder:SpecialFolderConst): ^IFolder;
function DeleteFile(FileSpec:BSTR; Force:bool);
function DeleteFolder(FolderSpec:BSTR; Force:bool);
function MoveFile(Source:BSTR; Destination:BSTR);
function MoveFolder(Source:BSTR; Destination:BSTR);
function CopyFile(Source:BSTR; Destination:BSTR; OverWriteFiles:bool);
function CopyFolder(Source:BSTR; Destination:BSTR; OverWriteFiles:bool);
function CreateFolder(Path:BSTR): ^IFolder;
function CreateTextFile(FileName:BSTR; Overwrite:bool; Unicode:bool): ^ITextStream;
function OpenTextFile(FileName:BSTR; IOMode:IOMode; Create:bool; Format:Tristate): ^ITextStream;
示例代码是 UMU Script Tools 里的一个小工具,用来删除空文件,主要思路是递归查找指定目录下的所有文件,遇到大小为 0 的文件则删除。请点击下面的缩略图: