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
<source lang="vbnet"> 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
</source>
Get Available Free Space for a Drive
<source lang="vbnet"> 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
</source>
Get Drive File System Format
<source lang="vbnet"> 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
</source>
Get Root Directory for each Drive
<source lang="vbnet"> 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
</source>
Get the Drive Type
<source lang="vbnet"> 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
</source>
Get Total Free Space Drive
<source lang="vbnet"> 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
</source>
Get Volumn Label for a Drive
<source lang="vbnet"> 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
</source>
Is Your Drive Ready
<source lang="vbnet"> 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
</source>
List each folder at the root of your C drive
<source lang="vbnet"> 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
</source>
Print out all logical dirve letters
<source lang="vbnet"> 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
</source>