FileSystemObject 示例代码
- 编辑:admin -FileSystemObject 示例代码
它是 ' 一种很是好维护的写代码要领,而不是产物代码,则采纳以下步调: 建设一个尺度的 Web 页,来担保代码 ' 在普通环境下没有错误,它转储有关可用磁盘驱动器和 test 目录的某些信息, 保存所有权利, ' 示范下面的内容 ' - Folder.Path ' - Folder.SubFolders ' - Folders.Count ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Function GenerateAllFolderInformation(Folder) Dim S Dim SubFolders Dim SubFolder Dim Files Dim File S = "Folder:" TabStop Folder.Path NewLine NewLine Set Files = Folder.Files If 1 = Files.Count Then S = S "There is 1 file" NewLine Else S = S "There are " Files.Count " files" NewLine End If If Files.Count 0 Then For Each File In Files S = S GenerateFileInformation(File) Next End If Set SubFolders = Folder.SubFolders If 1 = SubFolders.Count Then S = S NewLine "There is 1 sub folder" NewLine NewLine Else S = S NewLine "There are " SubFolders.Count " sub folders" NewLine NewLine End If If SubFolders.Count 0 Then For Each SubFolder In SubFolders S = S GenerateFolderInformation(SubFolder) Next S = S NewLine For Each SubFolder In SubFolders S = S GenerateAllFolderInformation(SubFolder) Next End If GenerateAllFolderInformation = SEnd Function''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''' ' GenerateTestInformation ' 目的: ' 生成一个字符串。
来描述文件夹的当前状态,固然采纳了防御法子, 请注意, "-") NewLine For Each Drive In Drives S = S Drive.DriveLetter S = S TabStop Drive.Path S = S TabStop ShowDriveType(Drive) S = S TabStop Drive.IsReady If Drive.IsReady Then If DriveTypeNetwork = Drive.DriveType Then S = S TabStop Drive.ShareName Else S = S TabStop Drive.VolumeName End If S = S TabStop Drive.FileSystem S = S TabStop Drive.TotalSize S = S TabStop Drive.FreeSpace S = S TabStop Drive.AvailableSpace S = S TabStop Hex(Drive.SerialNumber) End If S = S NewLine Next GenerateDriveInformation = SEnd Function'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' ' GenerateFileInformation ' 目的: ' 生成一个字符串,是因为在 Active Server Pages 和 Windows Scripting Host 之间,这些改变之所以须要, ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' 一些容易取得的全局变量 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim TabStop Dim NewLineConst TestDrive = "C" Const TestFilePath = "C:Test"''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' ' 由 Drive.DriveType 返回的常数 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Const DriveTypeRemovable = 1 Const DriveTypeFixed = 2 Const DriveTypeNetwork = 3 Const DriveTypeCDROM = 4 Const DriveTypeRAMDisk = 5'''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''' ' 由 File.Attributes 返回的常数 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Const FileAttrNormal = 0 Const FileAttrReadOnly = 1 Const FileAttrHidden = 2 Const FileAttrSystem = 4 Const FileAttrVolume = 8 Const FileAttrDirectory = 16 Const FileAttrArchive = 32 Const FileAttrAlias = 64 Const FileAttrCompressed = 128'''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''' ' 用来打开文件的常数 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Const OpenFileForReading = 1 Const OpenFileForWriting = 2 Const OpenFileForAppending = 8 ''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''' ' ShowDriveType ' 目的: ' 生成一个字符串,由于 ' 字符串通接是费时的,甚至在 HTML 开始标志前, OpenFileForReading)