Home »
VB.Net »
VB.Net Programs
VB.Net program to get attributes of the specified file
By Nidhi Last Updated : November 15, 2024
Getting the attributes of a file in VB.Net
Here, we will get attributes of a specified file using the GetAttributes() method of the File class.
File attributes can be the following:
- Archive
- Compressed
- Device
- Hidden
- ReadOnly etc
Program/Source Code:
The source code to get attributes of the specified file is given below. The given program is compiled and executed successfully.
VB.Net code to get the attributes of the specified file
'VB.Net program to get attributes of the specified file.
Imports System.IO
Module Module1
Sub Main()
Try
Dim f As FileAttributes = File.GetAttributes("sample.txt")
Console.WriteLine("Attributes are :" & f.ToString())
Catch ex As FileNotFoundException
Console.WriteLine("File does not exist")
End Try
End Sub
End Module
Output
Attributes are :Archive
Press any key to continue . . .
Explanation
In the above program, we created the module Module1 that contains the Main() function. The Main() function is the entry point for the program. Here, we got the attributes of the "sample.txt" file. The GetAttributes() method returns the object of FileAttributes class and then we printed the attributes on the console screen.
VB.Net File Handling Programs »