一,fso.GetFile
提取文件相應的File 對象
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 = "文件名稱:" & f2.name & "<br>" s = s & "文件短路徑名:" & f2.shortPath & "<br>" s = s & "文件物理地址:" & f2.Path & "<br>" s = s & "文件屬性:" & f2.Attributes & "<br>" s = s & "文件大小: " & f2.size & "<br>" s = s & "文件類型: " & f2.type & "<br>" s = s & "文件創建時間: " & f2.DateCreated & "<br>" s = s & "最近訪問時間: " & f2.DateLastAccessed & "<br>" s = s & "最近修改時間: " & f2.DateLastModified response.write(s) %> |
其效果正如右鍵某文件,看到的具體屬性信息。
其中Attributes返回的數值“32”表示:(Archive)上次備份後已更改的文件。可讀寫。
其它值附錄如下:
Normal 0 普通文件。 沒有設置任何屬性。 ReadOnly 1 只讀文件。 可讀寫。 Hidden 2 隱藏文件。 可讀寫。 System 4 系統文件。 可讀寫。 Directory 16 文件夾或目錄。 只讀。 Archive 32 上次備份後已更改的文件。 可讀寫。 Alias 1024 鏈接或快捷方式。 只讀。 Compressed 2048 壓縮文件。 只讀。 |
二,file.move
作用將指定的文件或文件夾從某位置移動到另一位置。其實該方法仍然屬於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:/">查看下有沒有</a> |
簡單的剪切粘貼的功能實現。
三,File.Copy
同樣屬於fso.GetFile後的一個應用。就只是單純地拷貝文件到某位置。
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:/">查看下有沒有</a> |
和本ASP頁面同在目錄下的cnbruce.txt文件依然存在。