Home  >  Article  >  Backend Development  >  asp Deltextfile deletes the specified file in the specified folder instance tutorial

asp Deltextfile deletes the specified file in the specified folder instance tutorial

零下一度
零下一度Original
2017-05-22 14:29:522044browse

How can asp delete the specified files in the specified folder? Don't worry, let's take you through an asp Deltextfile tutorial on deleting specified files in a specified folder

There are 1.xls and 1.xls under the folder pic_1

Clear the folder, the code is as follows:

<%
dim path
Sub EmptyFolder(filespec) 
Dim fso 
Set fso = CreateObject("Scripting.FileSystemObject") 
fso.DeleteFolder(filespec) 
fso.CreateFolder(filespec) 
End Sub 
path=server.MapPath("/pic_1")
Emptyfolder(path)
%>

ASP deletes files, you must use the server's FileSystemObject object

Create a delete file function:

&#39;删除文件(适合所有文件) 
Function Deltextfile(fileurl)&#39;参数为相对路径 
 Set objFSO = CreateObject("Scripting.FileSystemObject") 
  fileurl = Server.MapPath(fileurl) 
  if objFSO.FileExists(fileurl) then &#39;检查文件是否存在 
   objFSO.DeleteFile(fileurl) 
  end if 
 Set objFSO = nothing 
End Function

2. Call the delete file function:

&#39;删除网站根目录下的a.txt文件
Deltextfile "\a.txt"

[Related recommendations]

1. Share asp fso delete file DeleteFile and folder DeleteFolder Example code

2. Summary asp fso tutorial--ASP Delete method

The above is the detailed content of asp Deltextfile deletes the specified file in the specified folder instance tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn