1. fso.GetFile
Extract the file corresponding 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 & "Latest visit time: " & f2.DateLastAccessed & "<br>" s = s & "Latest Modified Time: " & f2.DateLastModified response.write(s) %> |
The effect is just like the specific attribute information you see when right-clicking a file.
The value "32" returned by Attributes means: (Archive) the file that has been changed after the last backup. Readable and writeable.
Other values are appendix as follows:
Normal 0 Normal file. No properties are set. ReadOnly 1 Read-only file. Readable and writeable. Hidden 2 Hide files. Readable and writeable. System 4 system files. Readable and writeable. Directory 16 folder or directory. Read-only. Archive 32 Files that have been changed after the last backup. Readable and writeable. Alias 1024 link or shortcut. Read-only. Compressed 2048 Compressed file. Read-only. |
2. file.move
Used to move the 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 if there is any</a> |
Simple cut and paste function implementation.
3. File.Copy
Also belongs to an application after fso.GetFile. Just simply copying the file to a certain 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 if there is any</a> |
The cnbruce.txt file in the same directory as this ASP page still exists.