ASP中最常用的22個FSO檔案操作函式1 11

2021-05-26 01:58:11 字數 4639 閱讀 6191

1.檔案操作,取檔案大小asp asp**

3.fso顯示指定目錄下的所有檔案 廣告賺錢

function showfilelist(folderspec)  

』//功能:目錄存在時顯示此目錄下的所有檔案  

』//形參:目錄名  

』//返回值:成功為檔案列表,失敗為-1  

』//  

dim f, f1, fc, s  

if reportfolderstatus(folderspec) = 1 then  

set f = fso.getfolder(folderspec)  

set fc = f.files  

for each f1 in fc  

s = s & f1.name  

s = s & "|"  

next  

showfilelist = s  

else  

showfilelist = -1  

end if  

end function

4.使用fso複製指定檔案

function copyafile(sourcefile,destinationfile)  

』//功能:原始檔存在時,才能對檔案進行複製,目的檔案無影響  

』//形參:原始檔,目的檔案  

』//返回值:成功為1,失敗為-1  

』//  

dim myfile  

if reportfilestatus(sourcefile) = 1 then  

set myfile = fso.getfile(sourcefile)  

myfile.copy (destinationfile)  

copyafile = 1  

else  

copyafile = -1  

end if  

end function 

5.原始檔存在時目的檔案不存在時才能對檔案進行移動

』response.write moveafile("f:/123/4561.exe","f:/123/4562.txt")  

function moveafile(sourcefile,destinationfile)  

』//形參:原始檔,目的檔案  

』//返回值:成功為1,失敗為-1  

』//  

if reportfilestatus(sourcefile)=1 and  

reportfilestatus(destinationfileorpath) =-1 then  

fso.movefile sourcefile,destinationfileorpath  

moveafile = 1  

else  

moveafile = -1  

end if  

end function 

6.fso判斷指定檔案是否存在?

function reportfilestatus(filename)  

』//功能:判斷檔案是否存在  

』//形參:檔名  

』//返回值:成功為1,失敗為-1  

』//  

dim msg  

msg = -1  

if (fso.fileexists(filename)) then  

msg = 1  

else  

msg = -1  

end if  

reportfilestatus = msg  

end function 

7.fso讀取檔案建立日期

function showdatecreated(filespec)  

』//功能:檔案建立日期  

』//形參:檔名  

』//返回值:成功:檔案建立日期,失敗:-1  

』//  

dim f  

if reportfilestatus(filespec) = 1 then  

set f = fso.getfile(filespec)  

showdatecreated = f.datecreated  

else  

showdatecreated = -1  

end if  

end function

8.fso顯示檔案讀寫許可權屬性

function getattributes(filename)  

』//功能:顯示檔案屬性  

』//形參:檔名  

』//返回值:成功:檔案屬性,失敗:-1  

』//  

dim f,str  

if reportfilestatus(filename) = 1 then  

set f = fso.getfile(filename)  

select case f.attributes  

case 0 str="普通檔案。沒有設定任何屬性。 "  

case 1 str="唯讀檔案。可讀寫。 "  

case 2 str="隱藏檔案。可讀寫。 "  

case 4 str="系統檔案。可讀寫。 "  

case 16 str="資料夾或目錄。唯讀。 "  

case 32 str="上次備份後已更改的檔案。可讀寫。 "  

case 1024 str="鏈結或快捷方式。唯讀。 "  

case 2048 str=" 壓縮檔案。唯讀。"  

end select  

getattributes = str  

else  

getattributes = -1  

end if  

end function 

9.fso顯示指定檔案最後一次訪問/最後一次修改時間

』response.write showfileaccessinfo("檔案路徑")  

function showfileaccessinfo(filename,infotype)  

』//功能:顯示檔案建立時資訊  

』//形參:檔名,資訊類別  

』// 1 -----建立時間  

』// 2 -----上次訪問時間  

』// 3 -----上次修改時間  

』// 4 -----檔案路徑  

』// 5 -----檔名稱  

』// 6 -----檔案型別  

』// 7 -----檔案大小  

』// 8 -----父目錄  

』// 9 -----根目錄  

』//返回值:成功為檔案建立時資訊,失敗:-1  

』//  

dim f, s  

if reportfilestatus(filename) = 1 then  

set f = fso.getfile(filename)  

select case infotype  

case 1 s = f.datecreated 』// 1 -----建立時間  

case 2 s = f.datelastaccessed 』// 2 -----上次訪問時間  

case 3 s = f.datelastmodified 』// 3 -----上次修改時間  

case 4 s = f.path 』// 4-----檔案路徑  

case 5 s = f.name 』// 5 -----檔名稱  

case 6 s = f.type 』// 6-----檔案型別  

case 7 s = f.size 』// 7-----檔案大小  

case 8 s = f.parentfolder 』// 8 -----父目錄  

case 9 s = f.rootfolder 』// 8 -----根目錄  

end select  

showfileaccessinfo = s  

else  

showfileaccessinfo = -1  

end if  

end function 

廣告**

10.fso寫指定內容到文字檔案

11.利用fso讀取文字檔案內容

function readtxtfile(filename)  

const forreading = 1, forwriting = 2  

dim f, m  

if reportfilestatus(filename) = 1 then  

set f = fso.opentextfile(filename, forreading)  

m = f.readline  

』m = f.readall  

』f.skipline  

readtxtfile = m  

f.close  

else  

readtxtfile = -1  

end if  

end function

Visual Studio中最常用的13個快捷鍵

2009 04 30 15 26 佚名 中國it實驗室 字型大小 t t 本文將為大家介紹visual studio中最常用的13個快捷鍵,輔以的介紹一定能讓大家更加熟練地使用這些快捷鍵,提高工作效率。ad 2013雲計算架構師峰會超低價搶票中 1.f5 啟動除錯 2.f7 shift f7 顯示 ...

Visual Studio中最常用的13個快捷鍵

1.f5 啟動除錯 2.f7 shift f7 顯示 視窗或顯示設計器視窗 3.alt enter 顯示選中物件的屬性 這是個常用的windows快捷鍵,可以用顯示目錄和檔案的屬性 4.f6 shift f6 ctrl shift b 生成解決方案 生成專案 生成解決方案 5.shift alt c...

Visual Studio中最常用的13個快捷鍵

1.f5 啟動除錯 2.f7 shift f7 顯示 視窗或顯示設計器視窗 3.alt enter 顯示選中物件的屬性 這是個常用的windows快捷鍵,可以用顯示目錄和檔案的屬性 4.f6 shift f6 ctrl shift b 生成解決方案 生成專案 生成解決方案 5.shift alt c...