|
-
Nov 27th, 2009, 08:07 PM
#1
Thread Starter
New Member
-
Nov 27th, 2009, 08:45 PM
#2
Re: Need help getting Initial HDDSize
You should check out the DriveInfo class, which is a member of the System.IO namespace. You can create an instance directly by passing a drive letter to the constructor. You can also get a an array of instances for all drives on the system by calling the Shared GetDrives method. You can then loop through that array and use any or all elements. The DriveInfo class has properties for the values you're looking for.
-
Nov 27th, 2009, 08:46 PM
#3
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Please Elaborate, I am not familiar with VB.NET
-
Nov 27th, 2009, 09:05 PM
#4
Re: Need help getting Initial HDDSize
When I provide information like that I generally expect people to use it to do their own research and then make an effort at a solution for themselves. I'm more than happy to help if they have trouble doing that but I would expect to see the attempt first.
As this is your first post I will cut you a break and provide some code but, for future reference, if I say that you would need to use the DriveInfo class then I would expect that you can go to the MSDN Library documentation and/or the web in general and search for information on that class. Being unfamiliar with VB doesn't preclude you from searching the web.
Anyway, here's an example of using the DriveInfo class, taken straight from the MSDN documentation:
Code:
Imports System
Imports System.IO
Class Test
Public Shared Sub Main()
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
For Each d In allDrives
Console.WriteLine("Drive {0}", d.Name)
Console.WriteLine(" File type: {0}", d.DriveType)
If d.IsReady = True Then
Console.WriteLine(" Volume label: {0}", d.VolumeLabel)
Console.WriteLine(" File system: {0}", d.DriveFormat)
Console.WriteLine( _
" Available space to current user:{0, 15} bytes", _
d.AvailableFreeSpace)
Console.WriteLine( _
" Total available space: {0, 15} bytes", _
d.TotalFreeSpace)
Console.WriteLine( _
" Total size of drive: {0, 15} bytes ", _
d.TotalSize)
End If
Next
End Sub
End Class
'This code produces output similar to the following:
'
'Drive A:\
' File type: Removable
'Drive C:\
' File type: Fixed
' Volume label:
' File system: FAT32
' Available space to current user: 4770430976 bytes
' Total available space: 4770430976 bytes
' Total size of drive: 10731683840 bytes
'Drive D:\
' File type: Fixed
' Volume label:
' File system: NTFS
' Available space to current user: 15114977280 bytes
' Total available space: 15114977280 bytes
' Total size of drive: 25958948864 bytes
'Drive E:\
' File type: CDRom
'
'The actual output of this code will vary based on machine and the permissions
'granted to the user executing it.
-
Nov 27th, 2009, 09:12 PM
#5
Thread Starter
New Member
Re: Need help getting Initial HDDSize
I cant find System.IO, its not in references, any ideas?
-
Nov 27th, 2009, 09:20 PM
#6
Re: Need help getting Initial HDDSize
You don't need to find anything. System.IO is a namespace. If your project references any assemblies that contain members of the System.IO namespace then that namespace is available to you. As the DriveInfo class is declared the mscorlib.dll assembly, which every project references by default, the System.IO namespace MUST be available to you.
-
Nov 27th, 2009, 09:22 PM
#7
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Ok, I found out that mscorlib is already added, though, i get "DriveInfo is not Defined"
-
Nov 27th, 2009, 09:24 PM
#8
Re: Need help getting Initial HDDSize
Check out the second line of the code I posted.
-
Nov 27th, 2009, 09:25 PM
#9
Thread Starter
New Member
Re: Need help getting Initial HDDSize
I get a "'Imports' statements must precede any declarations."
-
Nov 27th, 2009, 09:33 PM
#10
Re: Need help getting Initial HDDSize
 Originally Posted by SweetZVB.NET
I get a "'Imports' statements must precede any declarations."
Just as the error message says. Notice that the Imports statements are at the very top of the code I posted? That's where Imports statements must be: at the very top of a code file.
It seems to me that you're missing some of the fundamentals of VB programming. Not a sin, but I'd suggest that that's what you should concentrate on first. Working through a beginner tutorial from start to finish can help with that. Here's a good one:
http://www.homeandlearn.co.uk/NET/vbNET.html
-
Nov 27th, 2009, 09:45 PM
#11
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Code:
Class Test
Public Shared Sub Main()
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
Dim hdname As String
For Each d In allDrives
If d.IsReady = True Then
hdname = d.VolumeLabel
End If
Next
End Sub
End Class
I tried that, but when i go into the other section of my code, it dosnt recognise the "hdname" variable
-
Nov 27th, 2009, 09:52 PM
#12
Re: Need help getting Initial HDDSize
You have declared 'hdname' as a local variable in the Main method. As such, it only exists in the main method. The use of local and member variables and the passing of data from one object to another would fall under the category of fundamentals. I suggest that you work your way through that tutorial I suggested to learn how the language and the Framework work, then go back and try to do things with them, armed with the knowledge of how to do things like get data in one place and use it in another.
-
Nov 27th, 2009, 09:54 PM
#13
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Ive been using that tutorial for a few months now, and at the moment, I am trying to test my knowledge to create a "Fake Windows Format" APP, and it is going perfectly, other than I need to grab the Users (C Label & Size. I really would appreciate more help, and i would be very greatfull. Would it help if i posted the whole source?
-
Nov 27th, 2009, 10:01 PM
#14
Re: Need help getting Initial HDDSize
As I said back in post #2:
You can create an instance directly by passing a drive letter to the constructor.
If you only and specifically want information about C: drive then there's no point to looping through all the drives on the system. You should simply create one DriveInfo object specifically for the C: drive. You can then get whatever property values you want from that object and do whatever you need to do with them, e.g. display them in a Label on a Form.
-
Nov 27th, 2009, 10:03 PM
#15
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Thats what im looking for, hehe, sorry if i wasnt clear, but all I need is the C: size and Label. I have searched all across the internet, and not much found that i clearly understood, If I were to post my source, would you be able to give me a bit of a tutorial?
-
Nov 27th, 2009, 10:22 PM
#16
Re: Need help getting Initial HDDSize
All the information you need has already been provided. You're welcome to post your code if you want but you laready have everything you need.
1. Create an instance of the DriveInfo class, passing the drive letter of the drive of interest to the constructor
If you've been working on that Home & Learn tutorial then you know how to create objects and you know how to pass arguments to methods. That's this is.
2. Once you've got your instance, you get the desired property values from it do with them whatever's appropriate. You've got a code example of that.
-
Nov 27th, 2009, 10:37 PM
#17
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Ok, I havnt got onto that part yet, so i barely understood that, If i posted my code, would you mind filling it in? I know this is just getting someone else to do my work for me, but I really want to get this done, I know im asking for a big favour. It would be GREATLY appreciated.
-
Nov 28th, 2009, 12:45 AM
#18
Thread Starter
New Member
Re: Need help getting Initial HDDSize
-
Nov 29th, 2009, 02:52 PM
#19
Thread Starter
New Member
Re: Need help getting Initial HDDSize
-
Nov 29th, 2009, 05:53 PM
#20
Thread Starter
New Member
Re: Need help getting Initial HDDSize
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|