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.