Introduction to ASP Programming (18): FSO Component file operation (bottom) _asp Foundation

Source: Internet
Author: User
one, FSO. GetFile
Extracts files corresponding to the file object

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 & "file short path name:" & F2.shortpath & "<br>"
s = S & "File Physical 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 & recent access time: & F2. Datelastaccessed & "<br>"
s = S & "Last modified:" & F2. DateLastModified
Response.Write (s)
%>



The effect is the right key to a file, see the specific property information.
Where the value "32" returned by attributes represents: (Archive) A file that has changed since the last backup. can read and write.

Other values are annexed below:


Normal 0 normal files. No properties are set.
ReadOnly 1 read-only files. can read and write.
Hidden 2 hidden files. can read and write.
System 4 Systems files. can read and write.
Directory 16 folders or directories. Read-only.
Archive 32 files that have changed since the last backup. can read and write.
Alias 1024 link or shortcut. Read-only.
Compressed 2048 compressed files. Read-only.



Two, File.move
Action moves the specified file or folder from one location to another. In fact, the method still belongs to the FSO. An application after the 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:\" > see if there is </a>



Simple Cut-and-paste function is implemented.

Three, File.Copy
Also belong to FSO. An application after the 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:\" > see if there is </a>



The cnbruce.txt files that are in the same directory as this ASP page still exist.

four, file. Delete
Obviously, the file 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:\" > View is not the file of </a>



Of course, the FSO has not finished, such as uploading files, ASP to HTML, etc. need to use the FSO. The more wonderful is still in the back.
Related Article

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.