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

x
?
Solved

How can i delete only READ--ONLY files?

Posted on 2004-10-03
3
Medium Priority
?
164 Views
Last Modified: 2012-05-05
Hi files,

I need to implement something that DELETE only READ-ONLY files... So, if a have FILE1.txt and FILE2.txt, but just FILE2.txt is read-only, i just will DELETE FILE2.txt.

Anyone imagine how could i do this?

Best regards.
0
Comment
Question by:joelsilva
[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
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 80 total points
ID: 12214648
this procedure will delete any files with read only:

procedure DeleteReadOnlyFiles(const Dir, Mask:string);
var
  S:TSearchRec;
begin
  if (FindFirst(Dir+Mask, faAnyFile-faDirectory, S)=0) then
  repeat
    if (S.Attr and faReadOnly)>0 then
    begin
      SetFileAttributes(PChar(Dir+s.Name), FILE_ATTRIBUTE_NORMAL);
      DeleteFile(Dir+S.Name)
    end
  until (FindNext(S)<>0);
  FindClose(S)
end;


call it like:

DeleteReadOnlyFiles('c:\', '*.txt')

will delete all read only files from the c:\ that match *.txt
0
 

Author Comment

by:joelsilva
ID: 12215439
You got it... Thank you very much.
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12217870
you can go further and improve the procedure adding the attributes you want to delete files for

procedure DeleteReadOnlyFiles(const Dir, Mask:string; const Attrs=faReadOnly);
var
  S:TSearchRec;
begin
  if (FindFirst(Dir+Mask, faAnyFile-faDirectory, S)=0) then
  repeat
    if (S.Attr and Attrs)>0 then
...

then the default would still be the same, but now you could call it with other attributes if you wanted

DeleteReadOnlyFiles('c:\', '*.txt', faHidden)

of course you would have to rename the procedure name and give it a more appropiate name

best regards
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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

721 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