我有我的VBscript,它会将特定文件夹(例如C :)中的数据转换为文件大小的文本文件。我的问题是,我的文件大小是转换为字节而不是kb。知道我怎么能修改这个脚本来获得kb的确切文件大小?下面是我的VBscript:
Dim fso
Dim ObjFolder
Dim ObjOutFile
Dim ObjFiles
Dim ObjFile
'Creating File System Object
Set fso = CreateObject("Scripting.FileSystemObject")
'Getting the Folder Object
Set ObjFolder = fso.GetFolder("C:\Users\User\Desktop\Folder A")
'Creating an Output File to write the File sizes
Set ObjOutFile = fso.CreateTextFile("C:\Users\User\Desktop\IDENTIFIYING ZERO FILE SIZE KB.txt")
'Getting the list of Files
Set ObjFiles = ObjFolder.Files
'Writing sizes and Path of each File to Output File
For Each ObjFile In ObjFiles
ObjOutFile.WriteLine(ObjFile.size & String(50 - Len(ObjFile.size), " ") & ObjFile.Path)
Next
ObjOutFile.Close
答案 0 :(得分:4)
将大小除以1024得到它以KB为单位并将值四舍五入到适当的位数(例如2):
For Each ObjFile In ObjFiles
size = Round(ObjFile.size / 1024, 2)
ObjOutFile.WriteLine size & String(50 - Len(size), " ") & ObjFile.Path
Next