dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB
Expertise: Beginner
Feb 23, 2004

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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)
DevX Staff
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date