Fso| programming |fso 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.
Second, 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>