Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete a file?

Posted on 1998-09-11
1
Medium Priority
?
158 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

715 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