<% ' +---------------------------------------------------------------------- ' | POPASP [ ASP MVC ] ' +---------------------------------------------------------------------- ' | Copyright (c) 2016 http://popasp.com All rights reserved. ' +---------------------------------------------------------------------- ' | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) ' +---------------------------------------------------------------------- ' | Author: popasp <1737025626@qq.com> ' +---------------------------------------------------------------------- Class POPASP_FILE '下面几个方法来自于POP_MVC ' 获取绝对路径 Function realPath( path ) realPath = POP_MVC.realPath( path ) End Function '获取文本文件内容 Function getContents( ByVal filePath ) getContents = POP_MVC.file_get_contents( filePath ) End Function ' 给文件写入内容,如果文件不存在,则尝试创建 Function putContents(filePath,content) putContents = POP_MVC.file_put_contents(filePath,content) End Function '向文件尾部追加内容 Function appendContents( ByRef filePath , ByRef append_contents) appendContents = POP_MVC.file_append_contents(filePath,append_contents) End Function '自动生成文件夹路径 Public Property Get CreateFolder( ByVal path ) CreateFolder = POP_MVC.CreateFolder( path ) End Property ''''''''''''''''''''''''''' '返回路径中的文件名部分 '如果参数为数组,则第一个参数对应路径,第二个参数为一boolean值,为真时返回不含后缀的文件名,为假为含后缀 Function baseName( byref arg ) dim bool,suffix,filePath bool = false '处理参数 if isArray( arg ) Then filePath = arg(0) if ubound(arg) > 0 then '含有两个参数 bool = Not is_empty( arg(1) ) end if else filePath = arg end if filePath = replace( filePath,"\","/" ) '将路径中的\,用/来替换 if POP_MVC.String.Exists( filePath, "/" ) then '如果口径中含有/ filePath = POP_MVC.String.rstr( filePath ,"/" ) '找最后一个/ filePath = mid(filePath,2) end if baseName = filePath if bool then '为真时,不含后缀 if POP_MVC.String.Exists( filePath, "." ) then '判断文件名中是否含有点 suffix = POP_MVC.String.rstr( filePath ,"." ) end if if suffix <> "" Then baseName = mid(baseName,1,len(baseName) - len(suffix) ) end if end if End Function '返回路径中的文件名的后缀,默认含. '如果参数为数组,则第一个参数对应路径,第二个参数为一boolean值,为真时返回不含点的文件名,为假为含点 Function extName( ByVal arg ) dim bool,filePath extName = "" bool = false '处理参数 if isArray( arg ) Then filePath = arg(0) if ubound(arg) > 0 then '含有两个参数 bool = (Not is_empty( arg(1) )) end if else filePath = arg end if filePath = baseName( filePath ) if POP_MVC.String.Exists( filePath, "." ) then '判断文件名中是否含有点 extName = POP_MVC.String.rstr( filePath ,"." ) end if if bool then '为值时不含点 extName = mid( extName,2 ) end if End Function ' 从类文件中取得内容,并且删除第一个与最后一个出现在asp代码标记 Function class_get_contents ( file ) dim str,start_,end_ str = file_get_contents(file) start_ = InStr(str,"<" & "%") end_ = InStrRev( str,"%" & ">" ) str= mid(str,start_ + 2,end_-3) asp_get_contents = str End Function '获取文件内容 Function file_get_contents( ByVal file_path ) file_get_contents = POP_MVC.file_get_contents(file_path) End Function ' 检测提供的路径文件是否为文件 Function isFile( path ) isFile = POP_MVC.fso.FileExists( POP_MVC.realPath(path) ) End Function '检测提供的路径文件夹是否存在 Public Function isFolder(path) isFolder = POP_MVC.fso.FolderExists(POP_MVC.realPath(path)) End Function '检测相对路径的文件或文件夹是否存在 Public Function isExists(ByVal path) isExists = isFile(path) or isFolder(path) End Function '删除文件或文件夹 Public Property Get remove( path ) if isFile( path ) then call POP_MVC.fso.deleteFile(POP_MVC.realPath(path),true) elseif isFolder( path ) then call POP_MVC.fso.deleteFolder(POP_MVC.realPath(path),true) end if End Property ' 获取某个文件的修改时间 Function fileSize ( filename ) dim file If Instr(filename,">")>0 Then set file = POP_MVC.fso.GetFile(filename) else set file = POP_MVC.fso.GetFile(POP_MVC.realPath(filename)) end if fileSize = file.size set file = nothing End Function ' 获取某个文件的修改时间 Function mtime ( filename ) dim file If Instr(filename,">")>0 Then set file = POP_MVC.fso.GetFile(filename) else set file = POP_MVC.fso.GetFile(POP_MVC.realPath(filename)) end if mtime = file.DateLastModified set file = nothing End Function '把一个或多个文件从一个位置移动到另一个位置。 sub rename( byval src , byval dst ) err.clear on error resume next dim realSrc,realDst realSrc = POP_MVC.realPath( src ) realDst = POP_MVC.realPath( dst ) var_export realDst if realSrc<>realDst then if not Me.isExists( realDst ) then POP_MVC.fso.movefile realSrc, realDst else POP_MVC.Warning( dst & "文件已经存在,重命名失败!" ) end if end if if err.number <> 0 then POP_MVC.exit( "文件重命名失败," & err.number & "," & err.description ) end if end sub End Class %>