joelsilva
asked on
How can i delete only READ--ONLY files?
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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:\',
of course you would have to rename the procedure name and give it a more appropiate name
best regards
ASKER