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

V

VB Programmer

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!
 
G

Guest

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
 
V

VB Programmer

Thanks Peter! You're great.

Peter Bromberg said:
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 said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top