為大家介紹vbs屬性之size屬性,供大家學(xué)習(xí)參考。
Size 屬性
對(duì)于文件,返回指定文件的字節(jié)數(shù);對(duì)于文件夾,返回該文件夾中所有文件和子文件夾的字節(jié)數(shù)。方便我們判斷文件的大小。
說(shuō)明
object.Size
object 應(yīng)為 File 或 Folder 對(duì)象的名稱(chēng)。
Folder 對(duì)象的 Size 屬性示例:
Function ShowFolderSize(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(filespec)
s = UCase(f.Name) " 大小為 " f.size " 字節(jié)。"
ShowFolderSize = s
End Function
有時(shí)候我們需要獲取一些文件的大小,來(lái)實(shí)現(xiàn)是否需要復(fù)制,下面是腳本之家小編寫(xiě)的代碼
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
f1="d:\webroot\news.html"
f2="d:\webroot2\news.html"
fsize=3000
set fn2=fso.GetFile(f1)
flsize2=fn2.size
fldate2=fn2.datelastmodified
set fn=fso.GetFile(f2)
flsize1=fn.size
fldate1=fn.datelastmodified
If fso.FileExists(f1) and flsize2>fsize and fldate2>fldate1 Then
fso.getfile(f1).copy(f2)
if err.number=0 then WriteHistory "成功"now()".........","log.txt"
end if
Sub WriteHistory(hisChars, path)
Const ForReading = 1, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(path, ForAppending, True)
f.WriteLine hisChars
f.Close
End Sub
主要功能是判斷f1的文件生成時(shí)間與大小,來(lái)確認(rèn)是否需要覆蓋第二個(gè)文檔f2,大家可以根據(jù)需要自己獲取。