开发者

How to get the size of a file in VB.NET?

开发者 https://www.devze.com 2023-04-12 15:26 出处:网络
So I\'m tasked with wri开发者_StackOverflow中文版ting 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,

So I'm tasked with wri开发者_StackOverflow中文版ting 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.


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.:

dir >myoutput.txt /s <dir>


I would just the CMD command below

dir >dirinfo.txt

Just replace the file name with whatever name and path you need. This will export the results to the test file.

0

精彩评论

暂无评论...
验证码 换一张
取 消