Solved

Delete a file?

Posted on 1998-09-11
1
154 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month6 days, 9 hours left to enroll

634 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