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.
精彩评论