Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 131,551 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,241 people online right now. Registration is fast and FREE... Join Now!




Drive letters

 
Reply to this topicStart new topic

Drive letters, I need code to retrieve ALL drive letters automatically

irab88
post 28 Jul, 2008 - 08:18 AM
Post #1


New D.I.C Head

*
Joined: 28 Jul, 2008
Posts: 8


My Contributions


I have been trying to find code that either retrieves all drive information about every drive, or just retrieves the drive letter ( such as the 'C' in 'C:\' or the whole 'C:\' ). All the information I have found is written for VB5 or VB6, which does not work with Visual Studio 2005 SE. Here is what I have so far, which retrives the data from a .txt file created by the user:

vb
Dim fileDrive As String
fileDrive = My.Computer.FileSystem.ReadAllText("C:\Program Files\ArchAN\Drive.txt")

Dim drive As System.IO.DriveInfo
drive = My.Computer.FileSystem.GetDriveInfo(fileDrive & ":\")
Dim space As Long = drive.AvailableFreeSpace
Dim fileSize As String
fileSize = My.Computer.FileSystem.ReadAllText("C:\Program Files\ArchAN\Space.txt")
Dim temp As Decimal

temp = (space / 1024 / 1024 / 1000)

If temp < fileSize Then
temp = Format(temp, "#,###.##")
Me.tmrCheck.Enabled = False
MessageBox.Show("Attention: the " & fileDrive & ":\ is getting full." & vbNewLine & "It is recomended that you archive older files to conserve space." & vbNewLine & vbNewLine & "space remaining: " & temp & " GB", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
NotifyIcon1.Visible = False
End
End If


I would like the program to retrieve the information from the computer automatically. After that, I can use the data anyway I want.

Any help would be great.
thanks,
--Ian
User is offlineProfile CardPM

Go to the top of the page


Jayman
post 28 Jul, 2008 - 10:40 AM
Post #2


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,819



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


Moved to VB.NET where it will get the attention it deserves.
User is offlineProfile CardPM

Go to the top of the page

AdamSpeight2008
post 28 Jul, 2008 - 11:52 AM
Post #3


LINQ D.I.C.

Group Icon
Joined: 29 May, 2008
Posts: 749



Thanked 48 times

Dream Kudos: 2025
My Contributions


The following code evaluates through all the drives
vb

For Each Drive as system.io.driveinfo in My.Computer.FileSystem.Drives
' do so processing of drive info
next

User is offlineProfile CardPM

Go to the top of the page

Damage
post 28 Jul, 2008 - 05:02 PM
Post #4


D.I.C Addict

Group Icon
Joined: 5 Jun, 2008
Posts: 728



Thanked 7 times

Dream Kudos: 75
My Contributions


this should work
vb

imports system.io
Private Sub HardDrives()
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(d.VolumeLabel)
Console.WriteLine(d.DriveFormat)
Console.WriteLine(" Available space to current user:{0, 15} bytes" + " " + d.AvailableFreeSpace.ToString)

Console.WriteLine(" Total available space: {0, 15} bytes" + " " + d.TotalFreeSpace.ToString)

Console.WriteLine(" Total size of drive: {0, 15} bytes " + " " + d.TotalSize.ToString)
End If
Next
End Sub




This post has been edited by born2c0de: 30 Jul, 2008 - 03:24 AM
User is offlineProfile CardPM

Go to the top of the page

irab88
post 29 Jul, 2008 - 10:31 AM
Post #5


New D.I.C Head

*
Joined: 28 Jul, 2008
Posts: 8


My Contributions


Thanks! Both of these helped a lot.
I'll post code as soon as I've integrated them into my project. icon_up.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 02:34AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month