VB.Net Tutorial/Stream File/FileInfo

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

FileInfo.IsReadOnly, FileAttributes.Hidden

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
False
False

Get File Attributes as a string

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

        fileDetail = My.ruputer.FileSystem.GetFileInfo("test.txt")
        Console.WriteLine("Attributes: " & fileDetail.Attributes.ToString())
    End Sub
End Class
Attributes: Archive, NotContentIndexed

Get file Creation Time, Last Access Time and Modified Time

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
Created: 11/05/2007 9:20:09 PM
Accessed: 11/05/2007 9:26:39 PM
Modified: 11/05/2007 9:26:04 PM

Get file extension name

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
.txt

Get file size

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

        fileDetail = My.ruputer.FileSystem.GetFileInfo("test.txt")
        Console.WriteLine("Size: " & fileDetail.Length & " byte(s)")
    End Sub
End Class
Size: 343984 byte(s)

My.Computer.FileSystem.GetFileInfo(""File Name"")

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
False
False

Set file attributes: Hidden, ReadOnly

Public Class Tester
    Public Shared Sub Main
    
        Dim fileDetail As IO.FileInfo = My.ruputer.FileSystem.GetFileInfo("yourfile.jpg")
        fileDetail.IsReadOnly = True
        fileDetail.Attributes = fileDetail.Attributes Or IO.FileAttributes.Hidden
    End Sub
End Class