FSO Use tutorial 2--FSO Delete files

Source: Internet
Author: User
Tags error code
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
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.