如何在VB.NET中获取文件的大小?
因此,我的任务是编写一个命令行应用程序,告诉您给定目录的文件大小。我基本上将复制命令 dir /s
的功能,但将结果输出到文本文件,以便稍后解析。使用 VB.NET,我需要获取目录的大小,但在 DirectoryInfo
类中似乎没有这样的现成属性。如何获取目录的大小?
编辑:如果有一个内置命令或开关可以在命令行中输入以自动将操作结果输出到 .txt 文件,那么这将使这变得更加容易。
So I'm tasked with writing a command line app that tells you the file size of a given directory. I'm basically going to replicate what the command dir /s <dir>
does, but output the result to a text file to make it available for parsing later on.
Using VB.NET, I'm at a place where I need to get the size of a directory, but it seems there's no such ready-made property in the DirectoryInfo
class. How do I get the size of a directory?
EDIT: If there's a built-in command or switch that can be typed into command line to automatically output the results of an operation to a .txt file then that would make this infinitely easier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FileInfo 中没有 Length 属性你的版本?
(诚然,DirectoryInfo 没有这样的属性 - 您需要定义自己的递归函数,基于 DirectoryInfo 对象探索子目录和子文件夹,并返回它们的大小总和)
此外,对于大多数命令,您可以使用
>
运算符将输出发送到文本文件,例如:FileInfo doesn't have a Length property in your version?
(Admittedly, DirectoryInfo doesn't have such a property - you'd need to define your own recursive function that explores the subdirectories and subfolders, based on a DirectoryInfo object, and returns the sum of their sizes)
Also, for most commands, you can send the output to a text file using the
>
operator, e.g.:我只需使用下面的 CMD 命令
即可将文件名替换为您需要的任何名称和路径。这会将结果导出到测试文件。
I would just the CMD command below
Just replace the file name with whatever name and path you need. This will export the results to the test file.