fso| Tutorial
How to use the FSO to delete files -fso Use tutorial 2
Starting from this article, we began to explain the various functions of FSO, so that you systematically have a comprehensive understanding of the FSO, including how to use the FSO to copy files, how to use the FSO to delete files, how to use the FSO to move files, how to use FSO to rename files, how to use the FSO open How to use the FSO to create files, how to use the FSO to read files, how to use the FSO to write files, how to use the FSO to determine whether the file exists and so on.
Second, fso delete files
Method: DeleteFile
Call Format:
FileSystemObject name. deletefile deleted file [, Force delete]
Precautions:
- deleted file: must be a file that already exists, otherwise a "source not found" error is generated ( error code:
- whether to force Delete: If the file property is read-only, this parameter must be set to true before it can be deleted, otherwise there will be a "no permission" error ( error code:); For a file that is locked, it will produce a " Error with no permission ".
Source code Example:
Deletes the File1.txt in the same directory as the ASP file.
The procedure is as follows: (deletefile.asp)
<%
'===================================================
' Author: Arisisi
' URL: http://www.alixixi.com/
' Source: FSO Delete File Example
' Time: December 17, 2005
'===================================================
Set fs = Server.CreateObject ("Scripting.FileSystemObject")
File = Server.MapPath ("File1.txt")
On Error Resume Next
Fs. DeleteFile file, True ' force deletion of read-only files
If Err.Number = Then
Response.Write File & "files do not exist!" "
Response.End
Elseif Err.Number = Then
Response.Write File & Files property is locked! "
Response.End
Elseif err.number <> 0 Then
Response.Write "Unknown error, error code:" & Err.Number
Response.End
Else
Response.Write "Successfully deleted files!" "& File
End If
%>