VB.Net by API/System.IO/FileInfo

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

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