Solved

Delete a file?

Posted on 1998-09-11
1
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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