|
Get a list of all the files, loop over each file and get its size. As you loop you accumulate the size in a variable. At the end of the loop your variable will contain the total size of all files in the directory you were looping over.
|
|
|
|
|
To simplify the steps, I have created two functions you can use.
1. The first function will get all files in specified directory. You will need to add them all up to get a total folder size.
2. The second function will convert from bytes to kilobytes.
* Note: I am not sure if you are using vb.net or asp.net. I used Vb.Net so you will see a message box in my first function
Enjoy!
'Get File sizes in directory
Public Shared Sub GetFilesSizesInDirectory(ByVal Dir As String)
'Declare a variable to recieve file name
Dim FileName As String
'Iterate through specified directory
For Each FileName In Directory.GetFiles(Dir)
'Get file info and out file size
Dim Info As FileInfo = New FileInfo(FileName)
MsgBox(FileName & " " & ToKilobytes(Info.Length) & " KB")
Next
End Sub
'Convert from bytes to kilobytes
Public Shared Function ToKilobytes(ByVal Key As Long) As Long
'Variable to recieve remainder
Dim Remainder As Long
'Result of calculation
Dim Result As Integer = Math.DivRem(Key, 1024, Remainder)
'If there is a remainder always round-up
If Remainder <> 0 Then
Result += 1
End If
Return Result
End Function
Tyquaun
-- modified at 22:53 Thursday 27th July, 2006
|
|
|
|
|
Tyquaun Hunter wrote: Note: I am not sure if you are using vb.net or asp.net
What is he's using VB.NET and ASP.NET?
VB.NET is a language. ASP.NET is a framework for writing web applications. The two are not mutually exclusive.
I think what you meant to say is: I'm not sure if you're using a Windows Forms application or a Web Forms application....
Actually, that's not really correct either, because what if it is a console application, or a windows service.... Never mind. It's Three in the Morning and it is too hot to sleep.
|
|
|
|
|
Actually, you are right. However, what I have noticed is when people say VB.net they mean winforms and asp.net, well it is assumed I am talking about ASP.net/VB.net because I am in a VB.net forum.
-- modified at 22:44 Thursday 27th July, 2006
|
|
|
|
|
i am using only Visual Basic.thank u for the solution
|
|
|
|
|
Hi,
We already have a windows service set up to write to binary file for "our" custom events. Need to translate this binary file into comma delimited text file - how would we go about doing that? Can we just some built in VS2005 functions?
any ideas/thoughts much appreciated.
Thank you for your time.
|
|
|
|
|
Se the post a few lines down entitled:
" Converting from a byte array to a string?"
|
|
|
|
|
Please don't cross post.
---
b { font-weight: normal; }
|
|
|
|
|
Im looking for the code to copy a complete folder with its entire contens to a target folder. I'm looking for this quite a while but i was unable to find it. Can anyone help me?
Thanks, Zaegra
--Zaegra--
|
|
|
|
|
Try this. It is a two step process.
1. Create your destination directory with the same name as your source directory.
2. Get all of the files in your source directory and copy it over to your newly created destination directory.
* Note: You should prompt the user that destination directory already exists and if it does, give them an option to overwrite it. If not, it will overwrite automatically. Also, you should prompt the user that the file exist that you are about to overwrite. I just bypass existing files. You might have to perform some other types of error handling, but fundamentally, everything you need is there.
Good Luck
Public Shared Sub CopyEntireDirectory(ByVal SourceDir As String, ByVal DestinationDir As String)
'Create Directory
Directory.CreateDirectory(DestinationDir)
'Declare a variable to recieve file name
Dim FileName As String
'Iterate through source directory
For Each FileName In Directory.GetFiles(SourceDir)
'Copy file with each iteration as long as the file does not exist
If File.Exists(DestinationDir & GetFileName(FileName)) = False Then
File.Copy(FileName, DestinationDir & GetFileName(FileName))
End If
Next
End Sub
Tyquaun
-- modified at 22:54 Thursday 27th July, 2006
|
|
|
|
|
Now hope it works, thanks!
--Zaegra--
|
|
|
|
|
Oh yes, one more question: does this copy the sub-folder in a directory to?? Should i try doing that with your code and by getting the names of each sub-folder? Thanks again, Zaegra
--Zaegra--
|
|
|
|
|
Yes. Get the name of each sub-folder and copy it over. If you are going to get nested folders(a sub-folder of a sub-folder) than it is going to get pretty complicated. Is that something you want to do?
|
|
|
|
|
Ehrm.. Im afraid so.. Because im making a program that can copy files and complete(!) folders to a target directory. But that should mean that.. i have to all names of all sub-folders in every folder? Thats going to be a lot of work, isn't there something more handy? If not, im going to try this and maybe send you the program if its ready?
Thanks Tyquan
--Zaegra--
|
|
|
|
|
Hey sorry it took so long to get back to you, but i have been busy. Here you go. This will copy directories recursively. Just replace the CopyEntireDirectory method I gave you with this:
Public Shared Sub CopyEntireDirectory(ByVal SourceDir As String, ByVal DestinationDir As String)
'Create Directory
Directory.CreateDirectory(DestinationDir)
'Declare a variable to recieve file name
Dim FileName As String
'Iterate through source directory
For Each FileName In Directory.GetFiles(SourceDir)
'Copy file with each iteration as long as the file does not exist
If File.Exists(DestinationDir & GetFileName(FileName)) = False Then
File.Copy(FileName, DestinationDir & GetFileName(FileName))
End If
Next
'Create directory recursively
Dim SubDirectory As String
For Each SubDirectory In Directory.GetDirectories(SourceDir)
If Not Directory.Exists(DestinationDir & GetFileName(SubDirectory)) Then
CopyEntireDirectory(SubDirectory, DestinationDir & "\" & GetFileName(SubDirectory) & "\")
End If
Next
End Sub
Tyquaun Hunter
|
|
|
|
|
Thanks Tyquan ! You've been a great help, thanks!
--Zaegra--
|
|
|
|
|
Hi,
i really need your help in this..
can i bind a data set in an html table not a datagrid? and how can i do so..i need examples.
i've created a data adapter, data set, and a data reader, after that i tried to bind the the data in the html table but it's now working
Thanks
|
|
|
|
|
Why would you want bind to an HTML table and not a datagrid?
|
|
|
|
|
Because i think the html table is more flexibe than a datagrid.
i want to view my results like this:
First Name DataBind
Last Name DataBind
Address DataBind
(This is for one person)
not like this:
Column1 Column2 Column3
DataBind DataBind DataBind
DataBind DataBind DataBind
DataBind DataBind DataBind
(This for more than one person)
do you think i can do this with a datagrid?
|
|
|
|
|
Yes, but you have to construct the datagrid yourself and not use the control that visual studio provides for you. Also, which probably makes more sense, is if you use a datareader and build the table yourself. This is much more efficient than a datagrid.
Tyquaun
|
|
|
|
|
You can use DataList for this purpose
as
and provide your data to be shown in ItemTemplate tag in html ..
like this
<asp:Lable ID="lblName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"FirstName")%>' runat="server" />
put it in ItemTemplate of DataList
R A M
|
|
|
|
|
Heloo i want ro make a radix sort for a ashort project. i want to get the input from the user and also it will be in integer in visual basic
if possible give me guidence .. or send the radix sort code
faisal manzoor
|
|
|
|
|
If you would have Googled for "radix sort"[^], you would have found that the first hit is a good explanation of the algorithm, and contains sample implementations.
---
b { font-weight: normal; }
|
|
|
|
|
How can I do a calculation based on a formula entered via text box? Basically, I'm reading the result of a Analog to Digital Converter reading (ADC_Value)via RS232.
Examples of different formulas that need to be applied:
(LM60 Temperature) Result = 6.25/(ADC_Value - 424)
(LM50 Temperature) Result = 10/(ADC_Value - 500)
(A/D Voltage) Result = ADC_Value/1023 * 5
Basically I'd like to save the different formulas in a Database, each with a short description, and then load these into a combo. Then request the ADC_Value via RS232, take that value and manipulate it according to the combo selection, and display the result.
The reason I don't want to hard code the formulas is that should use a defferent sensor on the A/D Converter, then I would have to manually add this to the application.
Is there some sort of control that can build an expression from a string?
|
|
|
|
|
I don't know of any control that does that in VB.NET but I think you may have answered your own question...
RichardBerry wrote: Basically I'd like to save the different formulas in a Database, each with a short description, and then load these into a combo. Then request the ADC_Value via RS232, take that value and manipulate it according to the combo selection, and display the result.
That shouldn't be too hard.
After doing that you could create your own class that takes those values and performs the calculations. Think of all the variables you'll be using in the calculation and use those as arguments in functions that return the value. Those same varibles could be saved in your database and called, changed, inserted, deleted, whatever.
Just an idea. Or have i misunderstood you?
|
|
|
|