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
%>