如何将文件大小以 kB 为单位写入文本文件? [英] How to write file size in kB to text file?

查看:28
本文介绍了如何将文件大小以 kB 为单位写入文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的 VBscript,它将数据从特定文件夹(例如 C:)转换为具有文件大小的文本文件.我的问题是,我的文件大小正在转换为字节而不是 kb.知道如何修改此脚本以获取以 kb 为单位的确切文件大小吗?下面是我的 VB 脚本:

I have my VBscript which will convert the data from specific folder (e.g. C:) to text file with file sizes. My problem here is, my file size is converting to bytes instead of kb. Any idea how i can modify this script to get the exact file size in kb? Below is my 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

推荐答案

将大小除以 1024 得到 kB 并将该值四舍五入到适当的位数(例如 2):

Divide the size by 1024 to get it in kB and round the value to the appropriate number of digits (e.g. 2):

For Each ObjFile In ObjFiles
  size = Round(ObjFile.size / 1024, 2)
  ObjOutFile.WriteLine size & String(50 - Len(size), " ") & ObjFile.Path
Next

这篇关于如何将文件大小以 kB 为单位写入文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆