Advanced ASP programming (18): File Operations of the FSO component (II)

Source: Internet
Author: User

1. fso. GetFile
Extract File objects

1. getfile. asp

<%
Whichfile = Server. MapPath ("cnbruce.txt ")
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set f1 = fso. CreateTextFile (whichfile, true)
F1.Write ("This is a test. My Name is cnbruce .")
F1.Close
Set f2 = fso. GetFile (whichfile)

S = "file name:" & f2.name & "<br>"
S = s & "Short file path name:" & f2.20.path & "<br>"
S = s & "physical file address:" & f2.Path & "<br>"
S = s & "file attributes:" & f2.Attributes & "<br>"
S = s & "file size:" & f2.size & "<br>"
S = s & "file type:" & f2.type & "<br>"
S = s & "File Creation Time:" & f2.DateCreated & "<br>"
S = s & "last access time:" & f2.DateLastAccessed & "<br>"
S = s & "Last modified:" & f2.DateLastModified
Response. write (s)
%>

The result is as follows: Right-click a file to view the specific property information.
The value "32" returned by Attributes indicates: (Archive) the file that has been changed since the last backup. Read/write.

The appendix of other values is as follows:

Normal 0 common file. No attribute is set.
ReadOnly 1 read-only file. Read/write.
Hidden 2 hides the file. Read/write.
System 4 System file. Read/write.
Directory 16 folder or Directory. Read-only.
Archive 32 files changed after the last backup. Read/write.
Alias 1024 links or shortcuts. Read-only.
Compressed 2048. Read-only.

Ii. file. move
To move a specified file or folder from one location to another. In fact, this method still belongs to an application after fso. GetFile.

2. movefile. asp

<%
Whichfile = Server. MapPath ("cnbruce.txt ")
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set f1 = fso. CreateTextFile (whichfile, true)
F1.Write ("This is a test. My Name is cnbruce .")
F1.Close
Set f2 = fso. GetFile (whichfile)
F2.Move "C :\"
%>
<A href = "C: \"> check whether </a>

Simple cut and paste functions.

Iii. File. Copy
It also belongs to an application after fso. GetFile. Simply copy the file to a location.

3. copyfile. asp

<%
Whichfile = Server. MapPath ("cnbruce.txt ")
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set f1 = fso. CreateTextFile (whichfile, true)
F1.Write ("This is a test. My Name is cnbruce .")
F1.Close
Set f2 = fso. GetFile (whichfile)
F2.Copy "D :\"
%>
<A href = "D: \"> check whether </a>

The cnbruce.txt file in the same directory as the ASP page still exists.

4. file. Delete
Obviously, the object is deleted directly.

4. delfile. asp

<%
Whichfile = Server. MapPath ("cnbruce.txt ")
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set f1 = fso. CreateTextFile (whichfile, true)
F1.Write ("This is a test. My Name is cnbruce .")
F1.Close
Set f2 = fso. GetFile (whichfile)
F2.move "d :\"
Set f3 = fso. GetFile ("d: \ cnbruce.txt ")
F3.delete
%>
<A href = "d: \"> check if the file is not found. </a>

Of course, FSO is not over yet. For example, FSO is required for uploading files and converting ASP to HTML. What is even more amazing is that it remains behind.

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.