devxlogo

Changing the Attributes of a File

Changing the Attributes of a File

Say you’re trying to overwrite an existing file, but its attribute is set to “Readonly,” so it generates a “Permission Denied” error. The following code shows how to change the attribute to Normal mode to avoid this error:

     'Code shows hot to change the attribute of the file    'reference Microsoft Scripting Runtime(Scrrun.dll) must be added.    Dim fs As FileSystemObject    Dim Path as string,Path1 as string    Set fs = CreateObject("Scripting.FileSystemObject")    Path = "C:Test.bmp"    Path1 = "D:Test.bmp"        Dim f As File        If fs.FileExists(Path) Then            Set f = fs.GetFile(Path)            If f.Attributes  0 Then                 f.Attributes = 0 'Normal            End If        End If    Call fs.CopyFile(Path1, Path, True)
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist