Applecore Pages on Microsoft Access

Changing a File from Read-Only to Normal

In some cases (normally when a file is burnt to a CD-ROM) a file may have it's attributes set to include Read-only. One way of avoiding this is to zip the files before copying them to the CD-ROM. Another way is to change the attributes of any files in question once they have been copied to suitable media (such as a hard drive). A sample function is given below:

Public Function fChangeReadOnly(strFolder As String) As Long
'   Procedure to change a read-only file to normal
'   Accepts:
'       strFolder - the name of the folder to change the properties of files
'   Returns:
'       The number of files affected

    On Error GoTo E_Handle
    Dim strFile As String
    Dim lngFileAttr As Long
    If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
    strFile = Dir(strFolder, vbReadOnly)
    Do While strFile <> ""
        lngFileAttr = GetAttr(strFolder & strFile)
        If lngFileAttr And vbReadOnly Then
            SetAttr (strFolder & strFile), lngFileAttr - vbReadOnly
            fChangeReadOnly = fChangeReadOnly + 1
        End If
        strFile = Dir
    Loop
fExit:
    On Error Resume Next
    Exit Function
E_Handle:
    Select Case Err.Number
        Case 71
'   Drive not ready
        Case 75
'   Folder is on a drive that cannot have this attribute set (i.e. still on a CD-ROM)
        Case 76
'   Folder cannot be found
        Case Else
            MsgBox Err.Description & vbCrLf & "sChangeReadOnly", vbOKOnly + vbCritical, "Error: " & Err.Number
    End Select
    Resume fExit
End Function

Alternatively, you can change the property manually, by opening Windows Explorer, Right-Clicking on the required file, selecting Properties, and then removing the tick from 'Read-only'.

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 13:57:18