VB.Net program to set the attributes of the specified file

Here, we are going to learn how to set the attributes of the specified file in VB.Net?
Submitted by Nidhi, on January 10, 2021

Here, we will set attributes of a specified file using the SetAttributes() method of the File class.

File attributes can be the following:

  1. Archive
  2. Compressed
  3. Device
  4. Hidden
  5. ReadOnly etc

Program/Source Code:

The source code to set the attributes of the specified file is given below. The given program is compiled and executed successfully.

'VB.Net program to set the attributes of a specified file.

Imports System.IO

Module Module1
    Sub Main()
            Dim f1 As FileAttributes
            f1 = File.GetAttributes("abc.txt")

            Console.WriteLine("Attributes before Method Call are :" + f1.ToString())

            File.SetAttributes("abc.txt", FileAttributes.ReadOnly)

            Dim f2 As FileAttributes
            f2 = File.GetAttributes("abc.txt")

            Console.WriteLine("Attributes After Method Call are :" + f2.ToString())

        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module


Attributes before Method Call are :Archive
Attributes After Method Call are :ReadOnly
Press any key to continue . . .


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 set the ReadOnly attribute of the "sample.txt" file, and then we printed the attributes of the file on the console screen.

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.