VB.Net by API/System.IO/Directory
Содержание
Directory.CreateDirectory
Imports System.IO
Module Module1
Sub Main()
Console.WriteLine("Creating directories...")
Directory.CreateDirectory("D:\test01")
Directory.CreateDirectory("D:\Temp\Sample02")
Directory.CreateDirectory("Sample03")
Console.WriteLine("Directories created")
End Sub
End Module
Directory.Delete
Imports System.IO
Module Module1
Sub Main()
Try
Directory.Delete("C:\Sample01", True)
Catch E As Exception
Console.WriteLine("Error deleting directory C:\Sample01")
Console.WriteLine("Error {0}", E.Message)
End Try
End Sub
End Module
Directory.Exists
Imports System.IO
Module Module1
Sub Main()
Try
If (Directory.Exists("D:\test01")) Then
Console.WriteLine("D:\test01 already exists")
Else
Directory.CreateDirectory("C:\test01")
End If
Console.WriteLine("Directories created")
Catch E As Exception
Console.WriteLine("Error creating directory")
Console.WriteLine("Error: {0}", E.Message)
End Try
End Sub
End Module
Directory.GetCurrentDirectory()
Imports System.IO
Module Module1
Sub Main()
Dim Current As String
Dim Parent As DirectoryInfo
Try
Current = Directory.GetCurrentDirectory()
Parent = Directory.GetParent(Current)
Console.WriteLine("Current directory {0}", Current)
Console.WriteLine("Parent directory {0}", Parent.FullName)
Catch E As Exception
Console.WriteLine("Error determining parent directory")
Console.WriteLine(E.Message)
End Try
End Sub
End Module
Directory.GetDirectoryRoot
Imports System.IO
Public Class Tester
Public Shared Sub Main
Console.WriteLine(Directory.GetDirectoryRoot("c:\\Java_Dev"))
End Sub
End Class
Directory.GetFileSystemEntries
Imports System.IO
public class Test
public Shared Sub Main
Dim aryItems() As String
Dim strPath As String = "C:\Program Files"
Dim strItem As String
aryItems = Directory.GetFileSystemEntries(strPath)
For Each strItem In aryItems
If Directory.Exists(strItem) Then
Console.WriteLine("FOLDER " & strItem)
Else
Console.WriteLine("FILE " & strItem)
End If
Next strItem
End Sub
End class
Directory.GetLogicalDrives()
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
Directory.GetParent
Imports System.IO
Module Module1
Sub Main()
Dim Current As String
Dim Parent As DirectoryInfo
Try
Current = Directory.GetCurrentDirectory()
Parent = Directory.GetParent(Current)
Console.WriteLine("Current directory {0}", Current)
Console.WriteLine("Parent directory {0}", Parent.FullName)
Catch E As Exception
Console.WriteLine("Error determining parent directory")
Console.WriteLine(E.Message)
End Try
End Sub
End Module
Directory.Move
Imports System.IO
Public Class Tester
Public Shared Sub Main
Directory.Move("c:\\b", "c:\\a")
End Sub
End Class
Directory.SetCurrentDirectory
Imports System.IO
Module Module1
Sub Main()
Console.WriteLine("Current directory is {0}", Directory.GetCurrentDirectory())
Directory.SetCurrentDirectory("C:\")
Console.WriteLine("Current directory is {0}", Directory.GetCurrentDirectory())
End Sub
End Module