<p>FSO文件(File)对象属性<br /> DateCreated 返回该文件夹的创建<a href="http://www.111cn.net/tags.php/日期和时间">日期和时间</a><br /> DateLastAccessed 返回最后一次访问该文件的日期和时间<br /> DateLastModified 返回最后一次修改该文件的日期和时间<br /> Drive 返回该文件所在的驱动器的Drive对象<br /> Name 设定或返回文件的名字<br /> ParentFolder 返回该文件的父文件夹的Folder对象<br /> Path 返回文件的绝对路径,可使用长文件名<br /> ShortName 返回DOS风格的8.3形式的文件名<br /> ShortPath 返回DOS风格的8.3形式的文件绝对路径<br /> Size 返回该文件的大小(字节)<br /> Type 如果可能,返回一个文件类型的说明字符串<br /> FSO文件(File)对象方法<br /> FSO文件对象方法 用途<br /> CopyFile 拷贝一个或者多个文件到新路径<br /> CreateTextFile 创建文件并且返回一个TextStream对象<br /> DeleteFile 删除一个文件<br /> OpenTextFile 打开文件并且返回TextStream对象,以便读取或者追加</p> <p></p> <blockquote> <p>&lt;%<br /> &#39;================================================================<br /> &#39;= 系统版本:1.0 =<br /> &#39;= 文件版本:1.0 =<br /> &#39;= 文本创建日期:2005-10-31 =<br /> &#39;================================================================<br /> Class Cls_IO<br /> Private FileSystemObject</p> <p>Private Sub Class_Terminate()<br /> If IsObject(FileSystemObject) Then<br /> Set FileSystemObject = Nothing<br /> End If<br /> End Sub</p> <p>&#39;//创建FileSystemObject对象<br /> Public Function Init_Object()<br /> On Error Resume Next<br /> If Not IsObject(FileSystemObject) Then<br /> Set FileSystemObject = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br /> If Err.Number &lt;&gt; 0 Then<br /> Init_Object = False<br /> Err.Clear<br /> Exit Function<br /> Else<br /> Init_Object = True<br /> End If<br /> End If<br /> End Function</p> <p>Public Sub DeleteFile(ByVal Str)<br /> On Error Resume Next<br /> Call FileSystemObject.DeleteFile(Server.MapPath(&quot;../UpLoadFile/&quot;&amp;Str))<br /> End Sub</p> <p>Public Function IsFolder(ByVal Str)<br /> IsFolder = FileSystemObject.FolderExists(Str)<br /> End Function</p> <p><br /> Public Function ShowFolder(ByVal Str)<br /> Dim Obj_Folder,Obj_File<br /> Set Obj_Folder = FileSystemObject.GetFolder(Server.MapPath(Str))<br /> Set ShowFolder = Obj_Folder.Files<br /> Set Obj_Folder = Nothing<br /> End Function</p> <p>End Class<br /> %&gt;</p> <p>重命名文件:<br /> 复制代码 代码如下:<br /> Function reName(sourceName,destName)<br /> dim oFso,oFile<br /> set oFso=server.createobject(&quot;Scripting.FileSystemObject&quot;)<br /> set oFile=oFso.getFile(Server.mappath(sourceName))<br /> oFile.Name=destName<br /> Set oFso=Nothing<br /> Set oFile=Nothing<br /> End Function</p> <p>删除文件:<br /> 复制代码 代码如下:<br /> Function FSOdel(fileName)<br /> dim fso,f<br /> set fso = server.CreateObject(&quot;scripting.filesystemobject&quot;)<br /> f=server.MapPath(fileName)<br /> if fso.FileExists(f) then<br /> fso.DeleteFile f,true<br /> end if<br /> set f = nothing<br /> set fso = nothing<br /> End Function</p> <p>替换文件中的字符串:<br /> 复制代码 代码如下:<br /> Function FSOreplace(fileName,Target,repString)<br /> Dim objFSO,objCountFile,FiletempData<br /> Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br /> Set objCountFile = objFSO.OpenTextFile(Server.MapPath(fileName),1,True)<br /> FiletempData = objCountFile.ReadAll<br /> objCountFile.Close<br /> FiletempData=Replace(FiletempData,Target,repString)<br /> Set objCountFile=objFSO.CreateTextFile(Server.MapPath(fileName),True)<br /> objCountFile.Write FiletempData<br /> objCountFile.Close<br /> Set objCountFile=Nothing<br /> Set objFSO = Nothing<br /> End Function</p> <p>&lt;%</p> <p>&#39;*******************************************************<br /> &#39;函数名:CreateFolder(sPath)<br /> &#39;作 用: 创建目录<br /> &#39;参 数:sPath : 创建的相对目录路径<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> &#39;response.Write createfolder(&quot;/dgsunshine/UploadFile/demo1/&quot;)<br /> Function CreateFolder(sPath)<br /> On Error Resume Next</p> <p>Dim Fso,Arrfolder,Folder,i,j</p> <p>If sPath=&quot;&quot; then<br /> CreateFolder = False<br /> Exit Function<br /> End If</p> <p>If Left(sPath,1) = &quot;/&quot; Then<br /> Folder = &quot;/&quot;<br /> sPath = Mid(sPath,2,Len(sPath))<br /> Else<br /> Folder = &quot;./&quot;<br /> End If</p> <p>if Right(sPath,1) = &quot;/&quot; then sPath = Left(sPath,Len(sPath)-1)</p> <p>ArrFolder = Split(sPath,&quot;/&quot;)</p> <p>Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>For i = 0 To Ubound(ArrFolder)<br /> If i = 0 then<br /> Folder = Folder &amp; ArrFolder(i) &amp; &quot;/&quot;<br /> Else<br /> Folder = Folder &amp; ArrFolder(i) &amp; &quot;/&quot;<br /> End If</p> <p>If Fso.folderExists(Server.MapPath(Folder)) = False then<br /> response.Write server.MapPath(folder)<br /> Fso.createFolder(Server.MapPath(Folder))<br /> End If</p> <p>Next<br /> Set Fso = nothing</p> <p>If Err.Number &lt;&gt; 0 then<br /> Err.clear()<br /> CreateFolder = False<br /> Else<br /> CreateFolder = True<br /> End If<br /> End function</p> <p><br /> Function getFile(paramFilePath)<br /> Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br /> Set Fso_Read = fso.OpenTextFile(Server.MapPath(paramFilePath),1,false,-2)<br /> getFile = Fso_Read.readall<br /> Set Fso_Read = Nothing<br /> Set Fso = Nothing<br /> End Function</p> <p>&#39;*******************************************************<br /> &#39;函数名:CreateFile(paramFileContent,paramFilePath)<br /> &#39;作 用: 创建文件<br /> &#39;参 数:paramFileContent &#39;文件的内容<br /> &#39; paramFilePath &#39;文件名(不包括路径)<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function CreateFile(paramFileContent,paramFilePath)<br /> On Error Resume Next<br /> Dim Fso,fWrite</p> <p>Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br /> Set fWrite = Fso.CreateTextFile(Server.Mappath(paramFilePath),true)</p> <p>fWrite.write paramFileContent<br /> fWrite.close()<br /> Set fWrite = nothing<br /> Set Fso = nothing</p> <p>If Err.number &lt;&gt; 0 Then<br /> Err.clear()<br /> CreateFile = False<br /> Else<br /> CreateFile = True<br /> End If<br /> End Function</p> <p>&#39;*******************************************************<br /> &#39;函数名:DelFile(FilePath)<br /> &#39;作 用: 删除文件<br /> &#39;参 数:FilePath &#39;文件路径 多个文件用&quot;|&quot;隔开<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function DelFile(FilePath)<br /> On Error Resume Next<br /> Dim fso,arrFile,i</p> <p>If GetSafeStr(FilePath,&quot;&quot;)=&quot;&quot; then<br /> CreateFolder = false<br /> Exit Function<br /> End If</p> <p>arrFile = Split(FilePath,&quot;|&quot;)<br /> Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>for i=0 to UBound(arrFile)<br /> FilePath = arrFile(i)<br /> If Fso.FileExists(Server.MapPath(FilePath)) then<br /> Fso.DeleteFile Server.MapPath(FilePath)<br /> End If<br /> Next<br /> Set fso = nothing</p> <p>If Err then<br /> Err.clear()<br /> DelFile = false<br /> Else<br /> DelFile = true<br /> End If<br /> End Function</p> <p>&#39;*******************************************************<br /> &#39;函数名:DelFolder(FolderPath)<br /> &#39;作 用: 删除目录<br /> &#39;参 数:FolderPath &#39;目录路径 &#39;多个目录用&quot;|&quot;分隔<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function DelFolder(FolderPath)<br /> On Error Resume Next<br /> Dim Fso,arrFolder,i</p> <p>If GetSafeStr(FolderPath,&quot;&quot;)=&quot;&quot; then<br /> DelFolder = false<br /> Exit Function<br /> End If</p> <p>arrFolder = Split(FolderPath,&quot;|&quot;)<br /> Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>For i=0 to UBound(arrFolder)<br /> FolderPath = arrFolder(i)<br /> If Fso.folderexists(Server.MapPath(FolderPath)) then<br /> Fso.deleteFolder Server.MapPath(FolderPath)<br /> End If<br /> Next</p> <p>If Err then<br /> Err.clear()<br /> DelFolder = false<br /> &#39;ShowError &quot;删除目录失败&quot;,&quot;&quot;<br /> else<br /> DelFolder = true<br /> End If<br /> End Function</p> <p><br /> &#39;*******************************************************<br /> &#39;函数名:IsExistFile(FilePath)<br /> &#39;作 用: 判断文件或目录是否存在<br /> &#39;参 数:FilePath &#39;文件路径 多个文件用&quot;|&quot;隔开<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function IsExistFile(FilePath)<br /> On Error Resume Next<br /> Dim fso,arrFile,i</p> <p>If GetSafeStr(FilePath,&quot;&quot;)=&quot;&quot; then<br /> IsExistFile = false<br /> End If</p> <p>arrFile = Split(FilePath,&quot;|&quot;)<br /> Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>for i=0 to UBound(arrFile)<br /> FilePath = arrFile(i)<br /> If Fso.FileExists(Server.MapPath(FilePath)) then<br /> IsExistFile = True<br /> End If<br /> If Fso.folderexists(Server.MapPath(FilePath)) then<br /> IsExistFile = True<br /> End If<br /> Next<br /> Set fso = nothing</p> <p>If Err then<br /> Err.clear()<br /> IsExistFile = false<br /> &#39;ShowError &quot;判断文件或目录是否存在失败&quot;,&quot;&quot;<br /> else<br /> IsExistFile = true<br /> End If<br /> End Function</p> <p><br /> &#39;*******************************************************<br /> &#39;函数名:DelFile(FilePath)<br /> &#39;作 用: 删除文件或目录<br /> &#39;参 数:FilePath &#39;文件路径 多个文件用&quot;|&quot;隔开<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function DelFile(FilePath)<br /> On Error Resume Next<br /> Dim fso,arrFile,i</p> <p>If GetSafeStr(FilePath,&quot;&quot;)=&quot;&quot; then<br /> CreateFolder = false<br /> End If</p> <p>arrFile = Split(FilePath,&quot;|&quot;)<br /> Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>for i=0 to UBound(arrFile)<br /> FilePath = arrFile(i)<br /> If Fso.FileExists(Server.MapPath(FilePath)) then<br /> Fso.DeleteFile Server.MapPath(FilePath)<br /> End If<br /> If Fso.folderexists(Server.MapPath(FilePath)) then<br /> Fso.deleteFolder Server.MapPath(FilePath)<br /> End If<br /> Next<br /> Set fso = nothing</p> <p>If Err then<br /> Err.clear()<br /> DelFile = false<br /> &#39;ShowError &quot;删除文件或目录失败&quot;,&quot;&quot;<br /> else<br /> DelFile = true<br /> End If<br /> End Function</p> <p><br /> &#39;*******************************************************<br /> &#39;函数名:ReNameFile((oldName,newName)<br /> &#39;作 用: 重命名文件或目录<br /> &#39;参 数:strOldName &#39;原文件名 多个用&quot;|&quot;隔开<br /> &#39; strNewName &#39;新文件名 多个用&quot;|&quot;隔开<br /> &#39; 上面两个参数请保持一致<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function ReNameFile(strOldName,strNewName)<br /> On Error Resume Next<br /> Dim fso,arrOld,arrNew,i,oldName,newName</p> <p>old = GetSafeStr(strOldName,&quot;&quot;)<br /> Newfile = GetSafeStr(strNewName,&quot;&quot;)</p> <p>If old =&quot;&quot; or Newfile = &quot;&quot; then<br /> ReNameFile = false<br /> Exit Function<br /> End If</p> <p>arrOld = Split(strOldName,&quot;|&quot;)<br /> arrNew = Split(strNewName,&quot;|&quot;)</p> <p>If UBound(arrOld)&lt;&gt; UBound(arrNew) then<br /> ReNameFile = false<br /> Exit Function<br /> End If</p> <p>Set Fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br /> for i=0 to UBound(arrOld)<br /> oldName = Server.MapPath(arrOld(i))<br /> newName = Server.MapPath(arrNew(i))<br /> If Fso.FileExists(oldName) and not Fso.FileExists(newName) then<br /> fso.MoveFile oldName,newName<br /> &#39;ReNameFile = True<br /> End If<br /> Next<br /> Set fso = nothing</p> <p>If Err.Number &lt;&gt; 0 Then<br /> Err.clear()<br /> ReNameFile = false<br /> Else<br /> ReNameFile = True<br /> End If<br /> End Function</p> <p><br /> &#39;*******************************************************<br /> &#39;函数名:CopyFiles((TempSource,TempEnd)<br /> &#39;作 用: 复制文件或者目录<br /> &#39;参 数:TempSource &#39;源文件名 多个用&quot;|&quot;隔开<br /> &#39; TempEnd &#39;目的文件名 多个用&quot;|&quot;隔开<br /> &#39; 注意:上面两个参数请保持一致,并且都为完整路径,<br /> &#39; 已经经过Server.MapPath方法处理过<br /> &#39;返回值:成功 true , 失败 false<br /> &#39;*******************************************************<br /> Function CopyFiles(TempSource,TempEnd)<br /> On Error Resume Next<br /> Dim CopyFSO,arrSource,arrEnd</p> <p>CopyFiles = false<br /> Set CopyFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p> <p>If TempSource =&quot;&quot; or TempEnd = &quot;&quot; then<br /> ErrRaise &quot;复制文件或目录&quot;,&quot;条件为空&quot;<br /> CopyFiles = false<br /> Exit Function<br /> End If</p> <p>arrSource = Split(TempSource,&quot;|&quot;)<br /> arrEnd = Split(TempEnd,&quot;|&quot;)<br /> If UBound(arrSource) &lt;&gt; UBound(arrEnd) then<br /> CopyFiles= false<br /> Exit Function<br /> End If</p> <p>for i=0 to UBound(arrSource)<br /> srcName = arrSource(i)<br /> tarName = arrEnd(i)<br /> IF CopyFSO.FileExists(srcName) and not CopyFSO.FileExists(tarName) then<br /> CopyFSO.CopyFile srcName,tarName<br /> CopyFiles = true<br /> End If</p> <p>IF CopyFSO.FolderExists(srcName) and not CopyFSO.FolderExists(tarName)then<br /> CopyFSO.CopyFolder srcName,tarName<br /> CopyFiles = true<br /> End If<br /> Next<br /> Set CopyFSO = Nothing</p> <p>If Err then<br /> &#39;Err.clear()<br /> CopyFiles = false<br /> End If<br /> End Function<br /> %&gt;</p> </blockquote>
T:0.007385s,M:259.96 KB
返回顶部 留言