FSO Use Tutorial 3--FSO move files, rename files

Source: Internet
Author: User
Tags error code
fso| Tutorial

How to use the FSO to move files, rename files -FSO Use Tutorial 3

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.

Third, FSO mobile files, rename files

Method: MoveFile

Call Format:

FileSystemObject name. MoveFile source file, destination file

Precautions:

    • source file: must be a file that already exists, otherwise a "source cannot be found" error ( error code:
    • destination file: (1) The destination file must be a nonexistent file, or it will result in a "file exists" error ( error number =58), (2) If the destination file is in the same directory as the source file, then MoveFile's function is to change the file name If the destination file's directory is different from the directory in which the source file resides, the MoveFile function is to move the file.

Source code Example:

    • Rename the File1.txt under the same directory as the ASP file to NewFile1.txt.
      The procedure is as follows: (movefile.asp)
<%
'==================================================
' Author: Arisisi
' URL: http://www.alixixi.com/
' Source: FSO move file, rename file example
' Time: December 17, 2005
'==================================================
Set fs = Server.CreateObject ("Scripting.FileSystemObject")
Sfile = Server.MapPath ("File1.txt")
NFile = Server.MapPath ("NewFile1.txt")
On Error Resume Next
Fs. MoveFile Sfile, NFile
If Err.Number = Then
Response.Write File & "files do not exist!" "
Response.End
Elseif Err.Number = Then
Response.Write File & files already exist! "
Response.End
Elseif err.number <> 0 Then
Response.Write "Unknown error, error code:" & Err.Number
Response.End
Else
Response.Write "successfully renamed file!" "& Sfile &" for "&NFile&"
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.