Solved

Delete a file?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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