Solved

How can i delete only READ--ONLY files?

Posted on 2004-10-03
3
161 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 20 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

Technology Partners: 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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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