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

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

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

FileInfo.CreationTime

  
Public Class Tester
    Public Shared Sub Main
    
        Dim fileDetail As IO.FileInfo

        fileDetail = My.ruputer.FileSystem.GetFileInfo("test.txt")
        Console.WriteLine("Created: " & fileDetail.CreationTime)
        Console.WriteLine("Accessed: " & fileDetail.LastAccessTime)
        Console.WriteLine("Modified: " & fileDetail.LastWriteTime)
    End Sub
End Class


FileInfo.Extension

  
Public Class Tester
    Public Shared Sub Main
    
        Dim fileDetail As IO.FileInfo

        fileDetail = My.ruputer.FileSystem.GetFileInfo("test.txt")
        Console.WriteLine(fileDetail.Extension)
    End Sub
End Class


FileInfo.FullName

  
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


FileInfo.IsReadOnly

  
Public Class Tester
    Public Shared Sub Main
    
        Dim fileDetail As IO.FileInfo = My.ruputer.FileSystem.GetFileInfo("test.txt")
        Console.WriteLine(fileDetail.IsReadOnly)
        Console.WriteLine(CBool(fileDetail.Attributes And IO.FileAttributes.Hidden))
    End Sub
End Class


FileInfo.LastAccessTime

  
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


FileInfo.LastWriteTime

  
Public Class Tester
    Public Shared Sub Main
    
        Dim fileDetail As IO.FileInfo

        fileDetail = My.ruputer.FileSystem.GetFileInfo("test.txt")
        Console.WriteLine("Created: " & fileDetail.CreationTime)
        Console.WriteLine("Accessed: " & fileDetail.LastAccessTime)
        Console.WriteLine("Modified: " & fileDetail.LastWriteTime)
    End Sub
End Class


FileInfo.Length

  
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