473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How get total MB of a set of files in a dir?

I have a videos directory with a bunch of videos in it. The video filenames
begin with the username, such as "jsmith_01.mpeg". I want to find how many
MB of video files the current user has in the videos dir. Any idea how I can
do this?

Thanks!
Jan 26 '06 #1
2 1073
Something like so?
[C#}
public long GetTotalFilesSize( string path)
{
DirectoryInfo di = new DirectoryInfo( path );
FileInfo[] rgFiles = di.GetFiles("*.mpg");
long totalSize=0;
foreach(FileInfo fi in rgFiles)
{
totalSize+=fi.Length;
}
return totalSize;
}

[VB.Net]

Public Function GetTotalFilesSize(path As String) As Long
Dim di As New DirectoryInfo(path)
Dim rgFiles As FileInfo() = di.GetFiles("*.mpg")
Dim totalSize As Long = 0
Dim fi As FileInfo
For Each fi In rgFiles
totalSize += fi.Length
Next fi
Return totalSize
End Function 'GetTotalFilesSize

Cheers
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"VB Programmer" wrote:
I have a videos directory with a bunch of videos in it. The video filenames
begin with the username, such as "jsmith_01.mpeg". I want to find how many
MB of video files the current user has in the videos dir. Any idea how I can
do this?

Thanks!

Jan 26 '06 #2
Thanks Peter! You're great.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:64**********************************@microsof t.com...
Something like so?
[C#}
public long GetTotalFilesSize( string path)
{
DirectoryInfo di = new DirectoryInfo( path );
FileInfo[] rgFiles = di.GetFiles("*.mpg");
long totalSize=0;
foreach(FileInfo fi in rgFiles)
{
totalSize+=fi.Length;
}
return totalSize;
}

[VB.Net]

Public Function GetTotalFilesSize(path As String) As Long
Dim di As New DirectoryInfo(path)
Dim rgFiles As FileInfo() = di.GetFiles("*.mpg")
Dim totalSize As Long = 0
Dim fi As FileInfo
For Each fi In rgFiles
totalSize += fi.Length
Next fi
Return totalSize
End Function 'GetTotalFilesSize

Cheers
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"VB Programmer" wrote:
I have a videos directory with a bunch of videos in it. The video
filenames
begin with the username, such as "jsmith_01.mpeg". I want to find how
many
MB of video files the current user has in the videos dir. Any idea how I
can
do this?

Thanks!

Jan 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel | last post by:
in C# how do i get to total number of kilobytes of memroy total and available for the current machine?
36
by: Wei Su | last post by:
Hi, I have a text file abc.txt and it looks like: 12 34 56 23 45 56 33 56 78 ... .. .. ... .. .. I want to get how many rows totally in the text file, how to do this? Thanks.
10
by: Craig Bumpstead | last post by:
Hi, I was wondering the best and fastest way to determine how many lines are in a log file. At the moment I am simply doing a StreamReader.ReadLine and incrementing a counter until I reach...
12
by: grouped2000 | last post by:
g'day group, I need some code that will give me the total size of a folder. In the MSDN I've found some code, but I cannot figure out how to use this code at all ... I am quite new to .NET, I...
14
by: Kevin G. Anderson | last post by:
What: CAUG Meeting - QuickBooks IIF Files; Total Access Analyzer; CAUG Social When: Thursday, May 25, 2006, 6PM Who: Chris Monaghan and Kevin Anderson Where: The Information Management Group...
2
by: AtulSureka | last post by:
Hi, I want to determine the total number of files and folders in the given directory. I have a solution to go recursively on each folder and make a count . But I do not want to go recursively...
2
by: gaga | last post by:
hi all, i need to write a program - cash register for dummies, so to speak. here's the gist - enter the amount of pies that a person wants to get. A person can get either, 1, 2, 3, or 4 pizza...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
10
by: programmerboy | last post by:
As the subject says how can I check total # of files and folders in a particular folder and determine the total size of that folder. I will be using VB.NET. A small code snippet will be great. Thanks
8
by: W. eWatson | last post by:
I have an ordinary text file with a CR at the end of a line, and two numbers in each line. Is there some way to determine the number of lines (records) in the file before I begin reading it? --...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.