المشاركات : 10
المواضيع 6
:
: 3
الإنتساب : Aug 2016
السلام عليكم
عندي مجلد فيه مجموعة ملفات لها لواحق مختلفة
يعني
html php doc
اريد انا امسح جميع الملفات اللتي لها لاحقة .html من المجلد
المشاركات : 654
المواضيع 34
:
: 106
الإنتساب : Aug 2010
وعليكم السلام
PHP كود :
procedure DeleteFilesWithWildCard(Dir, Prefix, Suffix: String);
var
SRec: TSearchRec;
begin
{ Check the passed parameter, make sure it ends in a backslash }
if Length(Dir) = 0 then
Exit;
if Dir[Length(Dir)] <> '\' then
AppendStr(Dir, '\');
if FindFirst(Dir + Prefix + '*.' + Suffix, faAnyfile, SRec) = 0 then
try
{ We must call FindClose after the FindFirst succeeded, otherwise
the program looses a system handle. So use a try finally block. }
repeat
{ We have a hit. Check if it is a directory }
if (faDirectory and SRec.Attr) = 0 then
begin
{ It is a file, try to delete it. This may fail if the file
has the read-only attribute. If it does we show a message but
continue with other files if the user does not abort. }
if not SysUtils.DeleteFile(Dir + SRec.Name) then
begin
if MessageDlg(
'Cannot delete ' + SRec.Name +
', the file may be read-only. Do you want to abort the ' +
'operation?',
mtError,
[mbYes, mbNo, mbCancel],
0
) <> mrNo then
SysUtils.Abort;
end;
end;
{ Done with this hit, search for the next one. }
until
FindNext(SRec) <> 0;
finally
FindClose(SRec);
end;
end;
// Example: how to use DeleteFilesWithWildCard
procedure TForm1.Button1Click(Sender: TObject);
begin
DeleteFilesWithWildCard('C:\Users\Admin\Desktop\New folder', '', 'html');
end;
المصدر
سبحان الله وبحمده سبحان الله العظيم
كل من 2 users say قال شكرا ل Agmcz على المشاركة المفيدة2 users say Thank You to Agmcz for this post
• wadoud, GENNARO
المشاركات : 10
المواضيع 6
:
: 3
الإنتساب : Aug 2016
30-08-2016, 03:48 AM
(آخر تعديل لهذه المشاركة: 30-08-2016, 09:36 AM بواسطة Admin.)
هذا هو المطلوب اخي بارك الله فيك
استخدم هذا الاجراء
PHP كود :
procedure DeleteFiles(Path: string; Name: string);
var srec: TSearchRec;
begin
Path:=Path+'\';
if FindFirst(Path+Name, faAnyFile, srec)=0 then
begin
DeleteFile(Path+srec.Name);
while FindNext(srec)=0 do
DeleteFile(Path+srec.Name);
end;
FindCLose(srec);
end;
وهذا هو الاستدعاء
DeleteFiles('C:\Users\GENNARO\Desktop\New folder', '*.exe');