VB.Net by API/System.IO/DirectoryInfo — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:50, 26 мая 2010

DirectoryInfo.CreationTime

  

Imports System.IO
Module Module1
    Sub Main()
            Dim Dir As New DirectoryInfo("C:\WINNT\Temp")
            Console.WriteLine("Full name: {0}", Dir.FullName)
            Console.WriteLine("Creation time: {0}", Dir.CreationTime)
            Console.WriteLine("Last access time: {0}", Dir.LastAccessTime)
            Console.WriteLine("Last write time: {0}", Dir.LastWriteTime)
    End Sub
End Module


DirectoryInfo.FullName

  

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


DirectoryInfo.GetDirectories()

  

Imports System.IO
Module Module1
    Sub Main()
        Dim Root As New DirectoryInfo("C:\")
        Dim Files As FileInfo() = Root.GetFiles("*.*")
        Dim Dirs As DirectoryInfo() = Root.GetDirectories("*.*")
        Console.WriteLine("Root Directories")
        Dim DirectoryName As DirectoryInfo
        For Each DirectoryName In Dirs
            Try
                Console.Write(DirectoryName.FullName)
                Console.Write(" contains {0} files ", DirectoryName.GetFiles().Length)
                Console.WriteLine(" and {0} subdirectories ", DirectoryName.GetDirectories().Length)
            Catch E As Exception
                Console.WriteLine("Error accessing")
            End Try
        Next
    End Sub
End Module


DirectoryInfo.GetDirectories(String filter)

  
Imports System.IO
Module Module1
    Sub Main()
        Dim Root As New DirectoryInfo("C:\")
        Dim Files As FileInfo() = Root.GetFiles("*.*")
        Dim Dirs As DirectoryInfo() = Root.GetDirectories("*.*")
        Console.WriteLine("Root Directories")
        Dim DirectoryName As DirectoryInfo
        For Each DirectoryName In Dirs
            Try
                Console.Write(DirectoryName.FullName)
                Console.Write(" contains {0} files ", DirectoryName.GetFiles().Length)
                Console.WriteLine(" and {0} subdirectories ", DirectoryName.GetDirectories().Length)
            Catch E As Exception
                Console.WriteLine("Error accessing")
            End Try
        Next
    End Sub
End Module


DirectoryInfo.GetFiles

  
Imports System.IO
Module Module1
    Sub Main()
        Dim Root As New DirectoryInfo("C:\")
        Dim Files As FileInfo() = Root.GetFiles("*.*")
        Dim Dirs As DirectoryInfo() = Root.GetDirectories("*.*")
        Console.WriteLine("Root Files")
        Dim Filename As FileInfo
        For Each Filename In Files
            Try
                Console.Write(Filename.FullName)
                Console.Write(" Size: {0} bytes", Filename.Length)
                Console.WriteLine(" Last use: {0}", Filename.LastAccessTime)
            Catch E As Exception
                Console.WriteLine("Error accessing File")
            End Try
        Next
    End Sub
End Module


DirectoryInfo.LastAccessTime

  

Imports System.IO
Module Module1
    Sub Main()
            Dim Dir As New DirectoryInfo("C:\WINNT\Temp")
            Console.WriteLine("Full name: {0}", Dir.FullName)
            Console.WriteLine("Creation time: {0}", Dir.CreationTime)
            Console.WriteLine("Last access time: {0}", Dir.LastAccessTime)
            Console.WriteLine("Last write time: {0}", Dir.LastWriteTime)
    End Sub
End Module


DirectoryInfo.LastWriteTime

  

Imports System.IO
Module Module1
    Sub Main()
            Dim Dir As New DirectoryInfo("C:\WINNT\Temp")
            Console.WriteLine("Full name: {0}", Dir.FullName)
            Console.WriteLine("Creation time: {0}", Dir.CreationTime)
            Console.WriteLine("Last access time: {0}", Dir.LastAccessTime)
            Console.WriteLine("Last write time: {0}", Dir.LastWriteTime)
    End Sub
End Module


DirectoryInfo.Root

  
 
Imports System.IO
Public Class Tester
    Public Shared Sub Main

        Dim myDirectoryInfo As DirectoryInfo
        myDirectoryInfo = New DirectoryInfo("c:\\Java_dev")
        Console.WriteLine(myDirectoryInfo.Exists)
        
        Console.WriteLine(myDirectoryInfo.Name)
        Console.WriteLine(myDirectoryInfo.Parent.ToString)
        Console.WriteLine(myDirectoryInfo.Root.ToString)
    End Sub
End Class


New DirectoryInfo

  

Imports System.IO
Module Module1
    Sub Main()
        Dim Root As New DirectoryInfo("C:\")
        Dim Files As FileInfo() = Root.GetFiles("*.*")
        Dim Dirs As DirectoryInfo() = Root.GetDirectories("*.*")
        Console.WriteLine("Root Files")
        Dim Filename As FileInfo
        For Each Filename In Files
            Try
                Console.Write(Filename.FullName)
                Console.Write(" Size: {0} bytes", Filename.Length)
                Console.WriteLine(" Last use: {0}", Filename.LastAccessTime)
            Catch E As Exception
                Console.WriteLine("Error accessing File")
            End Try
        Next
    End Sub
End Module