Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Remove Read Only

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wendy - 30 Nov 2006 09:53 GMT
Hi

I'm trying to delete a file programatically, its set as readonly, I can't
find the fso option to do this can anyone help please?  This is what I've
got upto now.

thanks

Wendy

If (fso.FileExists(destnewsfile)) then fso.deletefile (destnewsfile)
Alex Dybenko - 30 Nov 2006 11:44 GMT
Hi,
here a sample API to change file attributes:
http://www.freevbcode.com/ShowCode.Asp?ID=660

Signature

Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

> Hi
>
[quoted text clipped - 7 lines]
>
> If (fso.FileExists(destnewsfile)) then fso.deletefile (destnewsfile)
Douglas J. Steele - 30 Nov 2006 12:22 GMT
That's probably overkill. VBA includes the SetAttr statement that will let
you change the attributes of a file.

To remove a file's Read-only attribute, while leaving the other attributes
the same, you can use:

SetAttr "full path to file", (GetAttr("full path to file") - vbReadOnly)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi,
> here a sample API to change file attributes:
[quoted text clipped - 11 lines]
>>
>> If (fso.FileExists(destnewsfile)) then fso.deletefile (destnewsfile)
Alex Dybenko - 30 Nov 2006 13:57 GMT
Hi Doug,
yes, you are right, forgot about native SetAttr
But Wendy also uses fso.deletefile instead of VBA's Kill :-)

Signature

Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

> That's probably overkill. VBA includes the SetAttr statement that will let
> you change the attributes of a file.
[quoted text clipped - 21 lines]
>>>
>>> If (fso.FileExists(destnewsfile)) then fso.deletefile (destnewsfile)
Douglas J. Steele - 30 Nov 2006 14:29 GMT
Yup.

No need for FSO at all, is there? <g>

Dim intAttribute As Integer

If Len(Dir(destnewsfile)) > 0 Then
 intAttribute = GetAttr(destnewfile)
 If (intAttribute And vbReadOnly) <> 0 Then
   SetAttr destnewfile, (intAttribute - vbReadOnly)
 End If
 Kill destnewsfile
End If

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi Doug,
> yes, you are right, forgot about native SetAttr
[quoted text clipped - 25 lines]
>>>>
>>>> If (fso.FileExists(destnewsfile)) then fso.deletefile (destnewsfile)
Tim Ferguson - 30 Nov 2006 16:40 GMT
> That's probably overkill. VBA includes the SetAttr statement that will
> let you change the attributes of a file.
[quoted text clipped - 4 lines]
> SetAttr "full path to file", (GetAttr("full path to file") -
> vbReadOnly)

That's probably overkill too. My help file says that the .Delete method of
the File object has a Force parameter that will kill readonly files...

 Set fil = fso.GetFile(somePathString)
 fil.Delete True

Hope that helps

Tim F
Douglas J. Steele - 30 Nov 2006 17:01 GMT
>> That's probably overkill. VBA includes the SetAttr statement that will
>> let you change the attributes of a file.
[quoted text clipped - 10 lines]
>  Set fil = fso.GetFile(somePathString)
>  fil.Delete True

You're right, but I don't like using FSO when it's not necessary!

Being picky, Wendy could simply use:

If (fso.FileExists(destnewsfile)) then fso.deletefile destnewsfile, True

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.