VB.Net/File Directory/Drive
Содержание
- 1 Display Drive Info: Drive Letter
- 2 Get Available Free Space for a Drive
- 3 Get Drive File System Format
- 4 Get Root Directory for each Drive
- 5 Get the Drive Type
- 6 Get Total Free Space Drive
- 7 Get Volumn Label for a Drive
- 8 Is Your Drive Ready
- 9 List each folder at the root of your C drive
- 10 Print out all logical dirve letters
Display Drive Info: Drive Letter
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.WriteLine(drive_info.Name)
Next drive_info
End Sub
End Class
Get Available Free Space for a Drive
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.RootDirectory.ToString)
If drive_info.IsReady() Then
Console.WriteLine( drive_info.AvailableFreeSpace().ToString)
End If
Next drive_info
End Sub
End Class
Get Drive File System Format
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.RootDirectory.ToString)
If drive_info.IsReady() Then
Console.WriteLine( drive_info.DriveFormat())
End If
Next drive_info
End Sub
End Class
Get Root Directory for each Drive
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.RootDirectory.ToString)
Next drive_info
End Sub
End Class
Get the Drive Type
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.DriveType().ToString)
Next drive_info
End Sub
End Class
Get Total Free Space Drive
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.RootDirectory.ToString)
If drive_info.IsReady() Then
Console.WriteLine( drive_info.TotalFreeSpace().ToString)
End If
Next drive_info
End Sub
End Class
Get Volumn Label for a Drive
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.RootDirectory.ToString)
If drive_info.IsReady() Then
Console.WriteLine( drive_info.VolumeLabel())
End If
Next drive_info
End Sub
End Class
Is Your Drive Ready
Imports System
Imports System.IO
Public Class MainClass
Shared Sub Main()
For Each drive_info As DriveInfo In DriveInfo.GetDrives()
Console.Write(drive_info.Name & " " )
Console.WriteLine(drive_info.IsReady().ToString)
Next drive_info
End Sub
End Class
List each folder at the root of your C drive
Imports System
Public Class MainClass
Shared Sub Main()
"List each folder at the root of your C drive
For Each strFolder As String In _
My.ruputer.FileSystem.GetDirectories("C:\")
"Add the item to the list
System.Console.WriteLine(strFolder)
Next
End Sub
End Class
Print out all logical dirve letters
Imports System.IO
Module Module1
Sub Main()
Dim DriveList As String() = Directory.GetLogicalDrives()
Dim Drive As String
Console.WriteLine("Logical Drives")
For Each Drive In DriveList
Console.WriteLine(Drive)
Next
End Sub
End Module