一些常用的FSO函数.docx
《一些常用的FSO函数.docx》由会员分享,可在线阅读,更多相关《一些常用的FSO函数.docx(17页珍藏版)》请在冰点文库上搜索。
一些常用的FSO函数
ASP中一些FSO方面的函数
'//==================================文件操作==================================
'取文件大小
FunctionGetFileSize(FileName)
'//功能:
取文件大小
'//形参:
文件名
'//返回值:
成功为文件大小,失败为-1
'//
Dimf
IfReportFileStatus(FileName)=1Then
Setf=fso.Getfile(FileName)
GetFileSize=f.Size
Else
GetFileSize=-1
Endif
EndFunction
'文件删除
FunctiondeleteAFile(filespec)
'//功能:
文件删除
'//形参:
文件名
'//返回值:
成功为1,失败为-1
'//
IfReportFileStatus(filespec)=1Then
fso.deleteFile(filespec)
deleteAFile=1
Else
deleteAFile=-1
Endif
EndFunction
'显示文件列表
FunctionShowFileList(folderspec)
'//功能:
目录存在时显示此目录下的所有文件
'//形参:
目录名
'//返回值:
成功为文件列表,失败为-1
'//
Dimf,f1,fc,s
IfReportFolderStatus(folderspec)=1Then
Setf=fso.GetFolder(folderspec)
Setfc=f.Files
ForEachf1infc
s=s&f1.name
s=s&""
Next
ShowFileList=s
Else
ShowFileList=-1
Endif
EndFunction
'!
!
!
'文件复制
FunctionCopyAFile(SourceFile,DestinationFile)
'//功能:
源文件存在时,才能对文件进行复制,目的文件无影响
'//形参:
源文件,目的文件
'//返回值:
成功为1,失败为-1
'//
DimMyFile
IfReportFileStatus(SourceFile)=1Then
SetMyFile=fso.GetFile(SourceFile)
MyFile.Copy(DestinationFile)
CopyAFile=1
Else
CopyAFile=-1
Endif
EndFunction
'文件移动
'Response.WriteMoveAFile("f:
\123\4561.exe","f:
\123\4562.txt")
FunctionMoveAFile(SourceFile,DestinationFile)
'//功能:
源文件存在时目的文件不存在时才能对文件进行移动
'//形参:
源文件,目的文件
'//返回值:
成功为1,失败为-1
'//
IfReportFileStatus(SourceFile)=1AndReportFileStatus(DestinationFileORPath)=
-1Then
fso.MoveFileSourceFile,DestinationFileORPath
MoveAFile=1
Else
MoveAFile=-1
Endif
EndFunction
'文件是否存在?
'Response.WriteReportFileStatus("G:
\soft\Delphi\my_pro\代码库.exe")
FunctionReportFileStatus(FileName)
'//功能:
判断文件是否存在
'//形参:
文件名
'//返回值:
成功为1,失败为-1
'//
Dimmsg
msg=-1
If(fso.FileExists(FileName))Then
msg=1
Else
msg=-1
EndIf
ReportFileStatus=msg
EndFunction
'文件创建日期
'Response.WriteShowDatecreated("G:
\soft\delphi\my_pro\代码库.exe")
'Response.WriteShowDatecreated("G:
\soft\delphi\my_pro\复件代码库.exe")
FunctionShowDatecreated(filespec)
'//功能:
文件创建日期
'//形参:
文件名
'//返回值:
成功:
文件创建日期,失败:
-1
'//
Dimf
IfReportFileStatus(filespec)=1Then
Setf=fso.GetFile(filespec)
ShowDatecreated=f.Datecreated
Else
ShowDatecreated=-1
Endif
EndFunction
'文件属性
'Response.WriteGetAttributes("G:
\soft\delphi\my_pro\复件代码库.exe")
FunctionGetAttributes(FileName)
'//功能:
显示文件属性
'//形参:
文件名
'//返回值:
成功:
文件属性,失败:
-1
'//
Dimf,Str
IfReportFileStatus(FileName)=1Then
Setf=fso.GetFile(FileName)
selectCasef.attributes
Case0Str="普通文件。
没有设置任何属性。
"
Case1Str="只读文件。
可读写。
"
Case2Str="隐藏文件。
可读写。
"
Case4Str="系统文件。
可读写。
"
Case16Str="文件夹或目录。
只读。
"
Case32Str="上次备份后已更改的文件。
可读写。
"
Case1024Str="链接或快捷方式。
只读。
"
Case2048Str="压缩文件。
只读。
"
Endselect
GetAttributes=Str
Else
GetAttributes=-1
Endif
EndFunction
'最后一次访问/最后一次修改时间
'Response.WriteShowFileAccessInfo("G:
\soft\delphi\my_pro\复件代码库.exe")
FunctionShowFileAccessInfo(FileName,InfoType)
'//功能:
显示文件创建时信息
'//形参:
文件名,信息类别
'//1-----创建时间
'//2-----上次访问时间
'//3-----上次修改时间
'//4-----文件路径
'//5-----文件名称
'//6-----文件类型
'//7-----文件大小
'//8-----父目录
'//9-----根目录
'//返回值:
成功为文件创建时信息,失败:
-1
'//
Dimf,s
IfReportFileStatus(FileName)=1then
Setf=fso.GetFile(FileName)
selectCaseInfoType
Case1s=f.Datecreated'//1-----
创建时间
Case2s=f.DateLastAccessed'//2-----上次访问
时间
Case3s=f.DateLastModified'//3-----上次修改
时间
Case4s=f.Path'//4
-----文件路径
Case5s=f.Name'//5
-----文件名称
Case6s=f.Type'//6
-----文件类型
Case7s=f.Size'//7
-----文件大小
Case8s=f.ParentFolder'//8-----
父目录
Case9s=f.RootFolder'//8-----
根目录
Endselect
ShowFileAccessInfo=s
ELse
ShowFileAccessInfo=-1
Endif
EndFunction
'写文本文件
FunctionWriteTxtFile(FileName,TextStr,WriteORAppendType)
ConstForReading=1,ForWriting=2,ForAppending=8
Dimf,m
selectCaseWriteORAppendType
Case1:
'文件进行写操作
Setf=fso.OpenTextFile(FileName,ForWriting,True)
f.WriteTextStr
f.Close
IfReportFileStatus(FileName)=1then
WriteTxtFile=1
Else
WriteTxtFile=-1
Endif
Case2:
'文件末尾进行写操作
IfReportFileStatus(FileName)=1then
Setf=fso.OpenTextFile(FileName,ForAppending)
f.WriteTextStr
f.Close
WriteTxtFile=1
Else
WriteTxtFile=-1
Endif
Endselect
EndFunction
'读文本文件
FunctionReadTxtFile(FileName)
ConstForReading=1,ForWriting=2
Dimf,m
IfReportFileStatus(FileName)=1then
Setf=fso.OpenTextFile(FileName,ForReading)
m=f.ReadLine
'm=f.ReadAll
'f.SkipLine
ReadTxtFile=m
f.Close
Else
ReadTxtFile=-1
Endif
EndFunction
'建立文本文件
'//==================================目录操作==================================
'取目录大小
FunctionGetFolderSize(FolderName)
'//功能:
取目录大小
'//形参:
目录名
'//返回值:
成功为目录大小,失败为-1
'//
Dimf
IfReportFolderStatus(FolderName)=1Then
Setf=fso.GetFolder(FolderName)
GetFolderSize=f.Size
Else
GetFolderSize=-1
Endif
EndFunction
'创建的文件夹
FunctioncreateFolderDemo(FolderName)
'//功能:
创建的文件夹
'//形参:
目录名
'//返回值:
成功为1,失败为-1
'//
Dimf
IfReportFolderStatus(Folderspec)=1Then
createFolderDemo=-1
Else
Setf=fso.createFolder(FolderName)
createFolderDemo=1
Endif
EndFunction
'!
!
!
'目录删除
FunctiondeleteAFolder(Folderspec)
'//功能:
目录删除
'//形参:
目录名
'//返回值:
成功为1,失败为-1
'//
Response.writeFolderspec
IfReportFolderStatus(Folderspec)=1Then
fso.deleteFolder(Folderspec)
deleteAFolder=1
Else
deleteAFolder=-1
Endif
EndFunction
'显示目录列表
FunctionShowFolderList(folderspec)
'//功能:
目录存在时显示此目录下的所有子目录
'//形参:
目录名
'//返回值:
成功为子目录列表,失败为-1
'//
Dimf,f1,fc,s
IfReportFolderStatus(folderspec)=1Then
Setf=fso.GetFolder(folderspec)
Setfc=f.SubFolders
ForEachf1infc
s=s&f1.name
s=s&""
Next
ShowFolderList=s
Else
ShowFolderList=-1
Endif
EndFunction
'!
!
!
!
'目录复制
FunctionCopyAFolder(SourceFolder,DestinationFolder)
'//功能:
源目录存在时,才能对目录进行复制,目的目录无影响
'//形参:
源目录,目的目录
'//返回值:
成功为1,失败为-1
'//
'DimMyFolder
'IfReportFolderStatus(SourceFolder)=1andReportFolderStatus
(DestinationFolder)=-1Then
'SetMyFolder=fso.GetFolder(SourceFolder)
fso.CopyFolderSourceFolder,DestinationFolder
CopyAFolder=1
'Else
CopyAFolder=-1
'Endif
EndFunction
'目录进行移动
FunctionMoveAFolder(SourcePath,DestinationPath)
'//功能:
源目录存在时目的目录不存在时才能对目录进行移动
'//形参:
源目录,目的目录
'//返回值:
成功为1,失败为-1
'//
IfReportFolderStatus(SourcePath)=1AndReportFolderStatus(DestinationPath)=0
Then
fso.MoveFolderSourcePath,DestinationPath
MoveAFolder=1
Else
MoveAFolder=-1
Endif
EndFunction
'判断目录是否存在
'Response.WriteReportFolderStatus("G:
\soft\delphi\my_pro\")
FunctionReportFolderStatus(fldr)
'//功能:
判断目录是否存在
'//形参:
目录
'//返回值:
成功为1,失败为-1
'//
Dimmsg
msg=-1
If(fso.FolderExists(fldr))Then
msg=1
Else
msg=-1
EndIf
ReportFolderStatus=msg
EndFunction
'目录创建时信息
FunctionShowFolderAccessInfo(FolderName,InfoType)
'//功能:
显示目录创建时信息
'//形参:
目录名,信息类别
'//1-----创建时间
'//2-----上次访问时间
'//3-----上次修改时间
'//4-----目录路径
'//5-----目录名称
'//6-----目录类型
'//7-----目录大小
'//8-----父目录
'//9-----根目录
'//返回值:
成功为目录创建时信息,失败:
-1
'//
Dimf,s
IfReportFolderStatus(FolderName)=1then
Setf=fso.GetFolder(FolderName)
selectCaseInfoType
Case1s=f.Datecreated'//1-----
创建时间
Case2s=f.DateLastAccessed'//2-----上次访问
时间
Case3s=f.DateLastModified'//3-----上次修改
时间
Case4s=f.Path'//4
-----文件路径
Case5s=f.Name'//5
-----文件名称
Case6s=f.Type'//6
-----文件类型
Case7s=f.Size'//7
-----文件大小
Case8s=f.ParentFolder'//8-----
父目录
Case9s=f.RootFolder'//9-----
根目录
Endselect
ShowFolderAccessInfo=s
ELse
ShowFolderAccessInfo=-1
Endif
EndFunction
FunctionDisplayLevelDepth(pathspec)
Dimf,n,Path
Setf=fso.GetFolder(pathspec)
Iff.IsRootFolderThen
DisplayLevelDepth="指定的文件夹是根文件夹。
"&RootFolder
Else
DoUntilf.IsRootFolder
Path=Path&f.Name&"
"
Setf=f.ParentFolder
n=n+1
Loop
DisplayLevelDepth="指定的文件夹是嵌套级为"&n&"的文件夹。
"&
Path
EndIf
EndFunction
'//==================================磁盘操作==================================
'驱动器是否存在?
'Response.WriteReportDriveStatus("C:
\")
FunctionReportDriveStatus(drv)
'//功能:
判断磁盘是否存在
'//形参:
磁盘
'//返回值:
成功为1,失败为-1
'//
Dimmsg
msg=-1
Iffso.DriveExists(drv)Then
msg=1
Else
msg=-1
EndIf
ReportDriveStatus=msg
EndFunction
'--------可用的返回类型包括FAT、NTFS和CDFS。
'Response.WriteShowFileSystemType("C:
\")
FunctionShowFileSystemType(drvspec)
'//功能:
磁盘类型
'//形参:
磁盘名
'//返回值:
成功为类型:
FAT、NTFS和CDFS,失败:
-1
'//
Dimd
IfReportDriveStatus(drvspec)=1Then
Setd=fso.GetDrive(drvspec)
ShowFileSystemType=d.FileSystem
ELse
ShowFileSystemType=-1
Endif
EndFunction
EndClass
%>