Solved

Delete a file?

Posted on 1998-09-11
1
141 Views
Last Modified: 2010-04-06
I've tried to use DeleteFile(Filename) to delete files. It seems to work ok but it won't delete files that are set to ReadOnly. How do I delete a file regardless of it's attributes?

thanks
0
Comment
Question by:Kmiller
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1339469
Hi KMiller,

Turn off the readonly attribute first using FileSetAttr(), and
then delete it as usual.

like :

var
 Attributes, NewAttributes: Word;

begin
 Attributes := FileGetAttr(FileName);
    { read file attributes }

 NewAttributes := Attributes;
 NewAttributes := NewAttributes and not faReadOnly;
    { remove readonly lock }

 FileSetAttr(FileName, NewAttributes);
         { ...write the new values }

 DeleteFile(FileName);
end;

Regards, Zif.



Regards, Zif.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now