VB.Net Tutorial/Stream File/Directory — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:56, 26 мая 2010
Содержание
Create a directory
Public Class Tester
Public Shared Sub Main
Try
My.ruputer.FileSystem.CreateDirectory("c:\\a")
Console.WriteLine("Directory created successfully.")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
Directory created successfully.
Get CurrentDirectory
Imports System.IO
Public Class Tester
Public Shared Sub Main
Console.WriteLine(Directory.GetCurrentDirectory)
End Sub
End Class
C:\Java_Dev\WEB\dev\VB
Get Directory contents
Imports System.IO
Public Class Tester
Public Shared Sub Main
If Directory.Exists("c:\\") Then
Dim directoryList As String() " array for directories
Dim i As Integer
directoryList = Directory.GetDirectories("c:\\")
For i = 0 To directoryList.Length - 1
Console.WriteLine(directoryList(i))
Next
End If
End Sub
End Class
c:\\Documents and Settings c:\\Java_Dev c:\\oracle c:\\Program Files c:\\RECYCLER c:\\System Volume Information c:\\SYSTEM.SAV c:\\Temp c:\\WINDOWS
Get Directory Creation Time
Option Strict On
Imports System.Collections.ObjectModel
Imports System.IO
Public Module FileSystem
Public Sub Main()
Dim dirPath As String = "c:\\"
If String.IsNullOrEmpty(dirPath) Then Exit Sub
If Not Directory.Exists(dirPath) Then Exit Sub
Dim dirs As ReadOnlyCollection(Of String) = My.ruputer.FileSystem.GetDirectories(dirPath)
For Each dir As String In dirs
Dim dirInfo As DirectoryInfo = New DirectoryInfo(dir)
Console.WriteLine("{0} : Created {1}", dirinfo.Name,dirInfo.CreationTime)
Next
End Sub
End Module
Documents and Settings : Created 27/08/2006 3:16:44 PM Java_Dev : Created 28/08/2006 5:04:26 PM oracle : Created 28/08/2006 7:04:13 PM Program Files : Created 27/08/2006 3:20:18 PM RECYCLER : Created 28/08/2006 7:30:41 PM System Volume Information : Created 27/08/2006 3:16:44 PM SYSTEM.SAV : Created 27/08/2006 11:01:08 PM Temp : Created 28/08/2006 7:19:38 PM WINDOWS : Created 27/08/2006 3:07:16 PM