Home >Backend Development >C#.Net Tutorial >Asp summary of file operation problems
读取一个文件相关信息的范例<br><br> " Response.Write "文件的建立日期:"&objFile.DateCreated&"<br>" Response.Write "文件的大小:"&objFile.Size&"<br>" Response.Write "文件的类型:"&objFile.Type&"<br>" Else Response.Write Server.MapPath("newfile.asp")&"不存在,无法读取相关信息" End If Set objFile = Nothing Set objFSO = Nothing '释放 FileSystemObject 对象实例内存空间 %>
动网论坛的代码,你参考一下吧 <!--#include file =conn.asp--> <!-- #include file="inc/const.asp" --> <title>--管理页面</title> <!--#include file=inc/forum_css.asp--> <meta> > "+"
系统空间占用情况 |
---|
|
ASP--文件操作类 设计版
'====================================================
'Version: AspFile 1.0
'Data: 2006.6.20
'CopyRight: (C) 2006 Evan.cn All Rights Reserved
'====================================================
'文件操作类
'文件名称
'文件大小
'文件创建
'FileName--文件名称
'DestinationFile--目标文件名称
'FileSize--获得文件大小
'FileCreatedDate--获得文件创建日期
'FileAttributes--获得文件属性
'ShowFileAccessInfo(InfoType)--获得文件属性
'CreateTxtFile()--创建文本文件
'WriteTxtFile(TextStr,WriteORAppendType)==写文本文件
'ReadTxtFile()--读取文本文件
'DeleteFile()--删除文件
'CopyFile()--拷贝文件
'MoveFile()--移动文件
'
'
Class Cls_FSO
Private o_Fso,s_FileName,s_FolderName,s_DestinationFile
Private s_FolderName,s_DestinationFolder
Private Sub Class_Initialize()
Set o_Fso = CreateObject("Scripting.FileSystemObject")
End Sub
Private Sub Class_Terminate()
Set o_Fso = Nothing
End Sub
'===============================================文件操作
'设置文件名字
Public Property Let FileName(Byval Values)
s_FileName=Values
'checkFile '检查文件
End Property
'设置目标文件名
Public Property Let DestinationFile(Byval Values)
s_DestinationFile=Values
End Property
'取文件大小
Public Property Get FileSize()
If fileExist Then
Dim f
Set f = o_Fso.Getfile(s_FileName)
FileSize = f.Size
Else
FileSize=0
End if
End Property
'取文件
Public Property Get FileCreatedDate()
If fileExist Then
Dim f
Set f = o_Fso.GetFile(s_FileName)
FileCreatedDate = f.DateCreated
Else
FileCreatedDate="1900-1-1"
End if
End Property
'取文件大小
Public Property Get FileAttributes()
If fileExist Then
Dim f,Str
Set f = o_Fso.GetFile(s_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
FileAttributes=Str
Else
FileAttributes="文件不存在或不可预测地属性"
End if
End Property
Public Function ShowFileAccessInfo(InfoType)
'//功能:显示文件创建时信息
'//形参:文件名,信息类别
'// 1 -----创建时间
'// 2 -----上次访问时间
'// 3 -----上次修改时间
'// 4 -----文件路径
'// 5 -----文件名称
'// 6 -----文件类型
'// 7 -----文件大小
'// 8 -----父目录
'// 9 -----根目录
'判断参数是否是数字
If fileExist Then
Dim f, s
Set f = o_Fso.GetFile(s_FileName)
Select Case InfoType
Case 1
s = f.DateCreated '// 1 -----创建时间
Case 2
s = f.DateLastAccessed '// 2 -----上次访问时间
Case 3
s = f.DateLastModified '// 3 -----上次修改时间
Case 4
s = f.path '// 4 ----- file path
case 5
s = f.name' // 5 ----- file name
case 6
s = f.type '// 6 ----- File type
Case 7
s = f.size' // 7 ------ The file size
case 8
s = f. ParentFolder '// 8 -----Parent Directory
Case 9
s = f.RootFolder '// 9 9 -----Root Directory
End Select
ShowFileAccessInfo=s
Else
ShowFileAccessInfo="File does not exist:("
End if
End Function
Private Function fileExist
fileExist = True
'Check file path
'Check if the file exists
If Not(o_Fso.FileExists(s_FileName)) Then
fileExist = False
End If
End Function
Private Function showErr(s_Msg )
Response.Write(s_Msg)
Set Fso=Nothing
Response.End()
End Function
Public Function CreateTxtFile()
'//Create an empty file
If fileExist Then
showErr "The file already exists:("
Else
Dim f
Set f=o_Fso.CreateTextFile(s_FileName)
f.Close
End If
End Function
Public Function WriteTxtFile(TextStr,WriteORAppendType)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim f, m
Select Case WriteORAppendType
; ## showErr "File writing Failed"
End if
Case 2: "Write operation at the end of the file
If fileExist Then
Set f = o_Fso.OpenTextFile(s_FileName, ForAppending)
.Close
using using using using ’ out through out through out through out out through out out through out ’’’'' ‐ ‐‐ ‐‐‐‐w _ = 2
Dim f, m
If fileExist Then
Set f = o_Fso.OpenTextFile(s_FileName, ForReading)
m = f.ReadLine
'm = f.ReadAll
' f.SkipLine
ReadTxtFile = m
f.Close
‐ ‐ ’s ’s ’s ‐ ‐ ‐ ‐ ‐ ‐‐ ‐ readTxtFile = ’ s ’ s ’ s ’ s ’ s ’ s ‐ ‐ ‐ ‐ ft . f. ## Public Function DeleteFile()
If fileExist Then
o_Fso.DeleteFile(s_FileName)
Else
showErr "The file no longer exists:("
End if
End Function
Public Function CopyFile()
'//Function: The file can be copied only when the source file exists, and the destination file has no effect
'//SourceFile=s_FileName
If fileExist Then
Dim MyFile
If s_FileName=s_DestinationFile Then
showErr "Prohibit copying the same file name to the same directory:("
End IF
Set MyFile = o_Fso.GetFile(s_FileName)
MyFile. Copy (s_DestinationFile)
Else
showErr "The file no longer exists"
End if
End Function
Public Function MoveFile()
If fileExist Then
Dim SourceFile
If s_FileName=s_DestinationFile Then
showErr "Prohibit moving a file with the same name to the same directory:("
End IF
o_Fso.MoveFile s_FileName,s_DestinationFile
Else
showErr "The file no longer exists:("
End If
End Function
'================ =============================== Directory operations
'Set directory name
Public Property Let FolderName (Byval Values)
s_FolderName=Values
'checkFolder 'Check the file
End Property
'Set the target directory name
Public Property Let DestinationFolder(Byval Values)
s_DestinationFolder= Values
End Property
'Get directory size
'Get directory creation information
'Determine whether directory exists
'Create directory
'Delete directory
'Copy directory
'Move directory
'Rename directory
'========== ====================================Traversal operation
End Class
Set myFile=new Cls_FSO
myFile.FileName=Server.MapPath("file.txt")
'myFile.CreateTxtFile()
myFile.WriteTxtFile "Test",2
myFile .DestinationFile=Server.MapPath("file2.txt")
myFile.CopyFile()
'myFile.FileName=Server.MapPath("file2.txt")
'myFile.DeleteFile()
response.Write(myFile.FileSize)
for i =0 to 8
response.Write(myFile.ShowFileAccessInfo(i) )
response.Write("
")
next
%>
The above is the detailed content of Asp summary of file operation problems. For more information, please follow other related articles on the PHP Chinese website!