一個使用fso的class,前面的文章也有提到。這里有比較多的一些實例。 % Dim MyFileFolder Set MyFileFolder = New FileFolderCls ''Response.Write MyFileFolder.MoveAFile("f:\123\4561.exe","f:\123\4562.txt") ''Response.Write MyFileFolder.MoveAFolder("f:\456","f:\ditg\456") ''Response.Write MyFileFolder.ShowFileSystemType("i:\") ''Response.Write MyFileFolder.CopyAFile("f:\123\4562.txt","f:\123\4563.txt") ''!!!! ''Response.Write MyFileFolder.CopyAFolder("f:\123\","f:\789\") ''Response.Write MyFileFolder.ShowFolderList("f:\ditg") ''Response.Write MyFileFolder.ShowFileList("f:\123\123") ''Response.Write MyFileFolder.DeleteAFile("f:\123\4562.txt") ''Response.Write MyFileFolder.DeleteAFolder("f:\456\") ''Response.Write MyFileFolder.CreateFolderDemo("f:\147\") ''Response.Write MyFileFolder.GetFileSize("f:\123\4563.txt") ''Response.Write MyFileFolder.GetFolderSize("f:\123\123.txt") ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",1)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",2)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",3)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",4)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",5)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",6)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",7)"br>" ''Response.Write MyFileFolder.ShowFileAccessInfo("f:\123\123.txt",8)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",1)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",2)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",3)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",4)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",5)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",6)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",7)"br>" ''Response.Write MyFileFolder.ShowFolderAccessInfo("f:\123\",8)"br>" ''Response.Write MyFileFolder.WriteTxtFile("f:\123\cexo.txt","",1)"br>" ''Response.Write MyFileFolder.WriteTxtFile("f:\123\cexo.txt","cexowxfdw",1)"br>" ''Response.Write MyFileFolder.WriteTxtFile("f:\123\cexo.txt",Chr(13)Chr(10) "cexowxfdw",2)"br>" ''Response.Write MyFileFolder.ReadTxtFile("f:\123\cexo.txt")"br>" Response.Write MyFileFolder.DisplayLevelDepth("F:\ditg\ditg\bumen\images")"br>" Class FileFolderCls Public fso Private Sub Class_Initialize() Set fso = CreateObject("Scripting.FileSystemObject") End Sub Private Sub Class_Terminate() Set fso = Nothing End Sub ''//==================================文件操作================================== ''取文件大小 Function GetFileSize(FileName) ''//功能:取文件大小 ''//形參:文件名 ''//返回值:成功為文件大小,失敗為-1 ''// Dim f If ReportFileStatus(FileName) = 1 Then Set f = fso.Getfile(FileName) GetFileSize = f.Size Else GetFileSize = -1 End if End Function ''文件刪除 Function DeleteAFile(filespec) ''//功能:文件刪除 ''//形參:文件名 ''//返回值:成功為1,失敗為-1 ''// If ReportFileStatus(filespec) = 1 Then fso.DeleteFile(filespec) DeleteAFile = 1 Else DeleteAFile = -1 End if End Function ''顯示文件列表 Function ShowFileList(folderspec) ''//功能:目錄存在時顯示此目錄下的所有文件 ''//形參:目錄名 ''//返回值:成功為文件列表,失敗為-1 ''// Dim f, f1, fc, s If ReportFolderStatus(folderspec) = 1 Then Set f = fso.GetFolder(folderspec) Set fc = f.Files For Each f1 in fc s = s f1.name s = s "|" Next ShowFileList = s Else ShowFileList = -1 End if End Function ''!!! ''文件復(fù)制 Function CopyAFile(SourceFile,DestinationFile) ''//功能:源文件存在時,才能對文件進(jìn)行復(fù)制,目的文件無影響 ''//形參:源文件,目的文件 ''//返回值:成功為1,失敗為-1 ''// Dim MyFile If ReportFileStatus(SourceFile) = 1 Then Set MyFile = fso.GetFile(SourceFile) MyFile.Copy (DestinationFile) CopyAFile = 1 Else CopyAFile = -1 End if End Function ''文件移動 ''Response.Write MoveAFile("f:\123\4561.exe","f:\123\4562.txt") Function MoveAFile(SourceFile,DestinationFile) ''//功能:源文件存在時目的文件不存在時才能對文件進(jìn)行移動 ''//形參:源文件,目的文件 ''//返回值:成功為1,失敗為-1 ''// If ReportFileStatus(SourceFile)=1 And ReportFileStatus(DestinationFileORPath) = -1 Then fso.MoveFile SourceFile,DestinationFileORPath MoveAFile = 1 Else MoveAFile = -1 End if End Function ''文件是否存在? ''Response.Write ReportFileStatus("G: oft\delphi\my_pro\代碼庫.exe") Function ReportFileStatus(FileName) ''//功能:判斷文件是否存在 ''//形參:文件名 ''//返回值:成功為1,失敗為-1 ''// Dim msg msg = -1 If (fso.FileExists(FileName)) Then msg = 1 Else msg = -1 End If ReportFileStatus = msg End Function ''文件創(chuàng)建日期 ''Response.Write ShowDateCreated("G: oft\delphi\my_pro\代碼庫.exe") ''Response.Write ShowDateCreated("G: oft\delphi\my_pro\復(fù)件 代碼庫.exe") Function ShowDateCreated(filespec) ''//功能:文件創(chuàng)建日期 ''//形參:文件名 ''//返回值:成功:文件創(chuàng)建日期,失敗:-1 ''// Dim f If ReportFileStatus(filespec) = 1 Then Set f = fso.GetFile(filespec) ShowDateCreated = f.DateCreated Else ShowDateCreated = -1 End if End Function ''文件屬性 ''Response.Write GetAttributes("G: oft\delphi\my_pro\復(fù)件 代碼庫.exe") Function GetAttributes(FileName) ''//功能:顯示文件屬性 ''//形參:文件名 ''//返回值:成功:文件屬性,失?。?1 ''// Dim f,Str If ReportFileStatus(FileName) = 1 Then Set f = fso.GetFile(FileName) Select Case f.attributes Case 0 Str="普通文件。沒有設(shè)置任何屬性。 " Case 1 Str="只讀文件??勺x寫。 " Case 2 Str="隱藏文件??勺x寫。 " Case 4 Str="系統(tǒng)文件??勺x寫。 " Case 16 Str="文件夾或目錄。只讀。 " Case 32 Str="上次備份后已更改的文件??勺x寫。 " Case 1024 Str="鏈接或快捷方式。只讀。 " Case 2048 Str=" 壓縮文件。只讀。" End Select GetAttributes = Str Else GetAttributes = -1 End if End Function ''最后一次訪問/最后一次修改時間 ''Response.Write ShowFileAccessInfo("G: oft\delphi\my_pro\復(fù)件 代碼庫.exe") Function ShowFileAccessInfo(FileName,InfoType) ''//功能:顯示文件創(chuàng)建時信息 ''//形參:文件名,信息類別 ''// 1 -----創(chuàng)建時間 ''// 2 -----上次訪問時間 ''// 3 -----上次修改時間 ''// 4 -----文件路徑 ''// 5 -----文件名稱 ''// 6 -----文件類型 ''// 7 -----文件大小 ''// 8 -----父目錄 ''// 9 -----根目錄 ''//返回值:成功為文件創(chuàng)建時信息,失敗:-1 ''// Dim f, s If ReportFileStatus(FileName) = 1 then Set f = fso.GetFile(FileName) Select Case InfoType Case 1 s = f.DateCreated ''// 1 ----- 創(chuàng)建時間 Case 2 s = f.DateLastAccessed ''// 2 -----上次訪問 時間 Case 3 s = f.DateLastModified ''// 3 -----上次修改 時間 Case 4 s = f.Path ''// 4 -----文件路徑 Case 5 s = f.Name ''// 5 -----文件名稱 Case 6 s = f.Type ''// 6 -----文件類型 Case 7 s = f.Size ''// 7 -----文件大小 Case 8 s = f.ParentFolder ''// 8 ----- 父目錄 Case 9 s = f.RootFolder ''// 8 ----- 根目錄 End Select ShowFileAccessInfo = s ELse ShowFileAccessInfo = -1 End if End Function ''寫文本文件 Function WriteTxtFile(FileName,TextStr,WriteORAppendType) Const ForReading = 1, ForWriting = 2 , ForAppending = 8 Dim f, m Select Case WriteORAppendType Case 1: ''文件進(jìn)行寫操作 Set f = fso.OpenTextFile(FileName, ForWriting, True) f.Write TextStr f.Close If ReportFileStatus(FileName) = 1 then WriteTxtFile = 1 Else WriteTxtFile = -1 End if Case 2: ''文件末尾進(jìn)行寫操作 If ReportFileStatus(FileName) = 1 then Set f = fso.OpenTextFile(FileName, ForAppending) f.Write TextStr f.Close WriteTxtFile = 1 Else WriteTxtFile = -1 End if End Select End Function ''讀文本文件 Function ReadTxtFile(FileName) Const ForReading = 1, ForWriting = 2 Dim f, m If ReportFileStatus(FileName) = 1 then Set f = fso.OpenTextFile(FileName, ForReading) m = f.ReadLine ''m = f.ReadAll ''f.SkipLine ReadTxtFile = m f.Close Else ReadTxtFile = -1 End if End Function ''建立文本文件 ''//==================================目錄操作================================== ''取目錄大小 Function GetFolderSize(FolderName) ''//功能:取目錄大小 ''//形參:目錄名 ''//返回值:成功為目錄大小,失敗為-1 ''// Dim f If ReportFolderStatus(FolderName) = 1 Then Set f = fso.GetFolder(FolderName) GetFolderSize = f.Size Else GetFolderSize = -1 End if End Function ''創(chuàng)建的文件夾 Function CreateFolderDemo(FolderName) ''//功能:創(chuàng)建的文件夾 ''//形參:目錄名 ''//返回值:成功為1,失敗為-1 ''// Dim f If ReportFolderStatus(Folderspec) = 1 Then CreateFolderDemo = -1 Else Set f = fso.CreateFolder(FolderName) CreateFolderDemo = 1 End if End Function ''!!! ''目錄刪除 Function DeleteAFolder(Folderspec) ''//功能:目錄刪除 ''//形參:目錄名 ''//返回值:成功為1,失敗為-1 ''// Response.write Folderspec If ReportFolderStatus(Folderspec) = 1 Then fso.DeleteFolder (Folderspec) DeleteAFolder = 1 Else DeleteAFolder = -1 End if End Function ''顯示目錄列表 Function ShowFolderList(folderspec) ''//功能:目錄存在時顯示此目錄下的所有子目錄 ''//形參:目錄名 ''//返回值:成功為子目錄列表,失敗為-1 ''// Dim f, f1, fc, s If ReportFolderStatus(folderspec) = 1 Then Set f = fso.GetFolder(folderspec) Set fc = f.SubFolders For Each f1 in fc s = s f1.name s = s "|" Next ShowFolderList = s Else ShowFolderList = -1 End if End Function ''!!!! ''目錄復(fù)制 Function CopyAFolder(SourceFolder,DestinationFolder) ''//功能:源目錄存在時,才能對目錄進(jìn)行復(fù)制,目的目錄無影響 ''//形參:源目錄,目的目錄 ''//返回值:成功為1,失敗為-1 ''// ''Dim MyFolder ''If ReportFolderStatus(SourceFolder) = 1 and ReportFolderStatus (DestinationFolder) = -1 Then ''Set MyFolder = fso.GetFolder(SourceFolder) fso.CopyFolder SourceFolder,DestinationFolder CopyAFolder = 1 ''Else CopyAFolder = -1 ''End if End Function ''目錄進(jìn)行移動 Function MoveAFolder(SourcePath,DestinationPath) ''//功能:源目錄存在時目的目錄不存在時才能對目錄進(jìn)行移動 ''//形參:源目錄,目的目錄 ''//返回值:成功為1,失敗為-1 ''// If ReportFolderStatus(SourcePath)=1 And ReportFolderStatus(DestinationPath)=0 Then fso.MoveFolder SourcePath, DestinationPath MoveAFolder = 1 Else MoveAFolder = -1 End if End Function ''判斷目錄是否存在 ''Response.Write ReportFolderStatus("G: oft\delphi\my_pro\") Function ReportFolderStatus(fldr) ''//功能:判斷目錄是否存在 ''//形參:目錄 ''//返回值:成功為1,失敗為-1 ''// Dim msg msg = -1 If (fso.FolderExists(fldr)) Then msg = 1 Else msg = -1 End If ReportFolderStatus = msg End Function ''目錄創(chuàng)建時信息 Function ShowFolderAccessInfo(FolderName,InfoType) ''//功能:顯示目錄創(chuàng)建時信息 ''//形參:目錄名,信息類別 ''// 1 -----創(chuàng)建時間 ''// 2 -----上次訪問時間 ''// 3 -----上次修改時間 ''// 4 -----目錄路徑 ''// 5 -----目錄名稱 ''// 6 -----目錄類型 ''// 7 -----目錄大小 ''// 8 -----父目錄 ''// 9 -----根目錄 ''//返回值:成功為目錄創(chuàng)建時信息,失?。?1 ''// Dim f, s If ReportFolderStatus(FolderName) = 1 then Set f = fso.GetFolder(FolderName) Select Case InfoType Case 1 s = f.DateCreated ''// 1 ----- 創(chuàng)建時間 Case 2 s = f.DateLastAccessed ''// 2 -----上次訪問 時間 Case 3 s = f.DateLastModified ''// 3 -----上次修改 時間 Case 4 s = f.Path ''// 4 -----文件路徑 Case 5 s = f.Name ''// 5 -----文件名稱 Case 6 s = f.Type ''// 6 -----文件類型 Case 7 s = f.Size ''// 7 -----文件大小 Case 8 s = f.ParentFolder ''// 8 ----- 父目錄 Case 9 s = f.RootFolder ''// 9 ----- 根目錄 End Select ShowFolderAccessInfo = s ELse ShowFolderAccessInfo = -1 End if End Function Function DisplayLevelDepth(pathspec) Dim f, n ,Path Set f = fso.GetFolder(pathspec) If f.IsRootFolder Then DisplayLevelDepth ="指定的文件夾是根文件夾。"RootFolder Else Do Until f.IsRootFolder Path = Path f.Name "br>" Set f = f.ParentFolder n = n + 1 Loop DisplayLevelDepth ="指定的文件夾是嵌套級為 " n " 的文件夾。br>" Path End If End Function ''//==================================磁盤操作================================== ''驅(qū)動器是否存在? ''Response.Write ReportDriveStatus("C:\") Function ReportDriveStatus(drv) ''//功能:判斷磁盤是否存在 ''//形參:磁盤 ''//返回值:成功為1,失敗為-1 ''// Dim msg msg = -1 If fso.DriveExists(drv) Then msg = 1 Else msg = -1 End If ReportDriveStatus = msg End Function ''--------可用的返回類型包括 FAT、NTFS 和 CDFS。 ''Response.Write ShowFileSystemType("C:\") Function ShowFileSystemType(drvspec) ''//功能:磁盤類型 ''//形參:磁盤名 ''//返回值:成功為類型:FAT、NTFS 和 CDFS,失?。?1 ''// Dim d If ReportDriveStatus(drvspec) = 1 Then Set d = fso. GetDrive(drvspec) ShowFileSystemType = d.FileSystem ELse ShowFileSystemType = -1 End if End Function End Class %>