日期:2012-04-08  浏览次数:21001 次

Asp中一些FSO方面的函数 
 
'//==================================文件操作==================================

'取文件大小
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

'!!!
'文件复制
Function CopyAFile(SourceFile,DestinationFile)
'//功能:源文件存在时,才能对文件进行复制,目的文件无影响
'//形参:源文件,目的文件
'//返回值:成功为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)
'//功能:源文件存在时目的文件不存在时才能对文件进行移动
'//形参:源文件,目的文件
'//返回值:成功为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:\soft\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


'文件创建日期
'Response.Write ShowDatecreated("G:\soft\delphi\my_pro\代码库.exe")
'Response.Write ShowDatecreated("G:\soft\delphi\my_pro\复件 代码库.exe")
Function ShowDatecreated(filespec)
'//功能:文件创建日期
'//形参:文件名
'//返回值:成功:文件创建日期,失败:-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:\soft\delphi\my_pro\复件 代码库.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="普通文件。没有设置任何属性。 "
Case 1 Str="只读文件。可读写。 "
Case 2 Str="隐藏文件。可读写。 "
Case 4 Str="系统文件。可读写。 "
Case 16 Str="文件夹或目录。只读。 "
Case 32 Str="上次备份后已更改的文件。可读写。 "
Case 1024 Str="链接或快捷方式。只读。 "
Case 2048 Str=" 压缩文件。只读。"
End select
GetAttributes = Str
Else
GetAttributes = -1
End if
End Function

'最后一次访问/最后一次修改时间
'Response.Write ShowFileAccessInfo("G:\soft\delphi\my_pro\复件 代码库.exe")
Function ShowFileAccessInfo(FileName,InfoType)
'//功能:显示文件创建时信息
'//形参:文件名,信息类别
'// 1 -----创建时间
'// 2 -----上次访问时间
'// 3 -----上次修改时间
'// 4 -----文件路径
'// 5 -----文件名称
'// 6 -----文件类型
'// 7 -----文件大小
'// 8 -----父目录
'// 9 -----根目录
'//返回值:成功为文件创建时信息,失败:-1
'//
Dim f, s
If ReportFileStatus(FileName) = 1 then
Set f = fso.GetFile(FileName)
select Case InfoType
Case 1 s = f.Datecreated '// 1 -----

创建时间
Case 2 s = f.DateLastAccessed '// 2 -----上次访问

时间
Case 3 s = f.DateLastModified '// 3 -----上次修改

时间