2

我有我的 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
4

1 回答 1

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
于 2013-09-04T22:00:05.617 回答