Topic: Delete Directory with non empty subdirectory and files
Do you have an example to Delete Directory with non empty subdirectory and files
Regards,
Pierre
My Visual Database → General → Delete Directory with non empty subdirectory and files
Do you have an example to Delete Directory with non empty subdirectory and files
Regards,
Pierre
Hello.
Check it out
function DeleteDirWithFiles(dir: string): boolean;
var
sl: TStringList;
i,c: integer;
begin
result := True;
sl := TStringList.Create;
sl.Text := GetFilesList(dir);
// delete all files
c := sl.Count-1;
for i := 0 to c do
if not DeleteFile(sl[i]) then
begin
ShowMessage('Can''t remove file '+sl[i]);
result := False;
end;
// delete directiries
sl.Text := GetDirectories(dir);
c := sl.Count-1;
for i := c downto 0 do
if not RemoveDir(sl[i]) then
begin
ShowMessage('Can''t remove dirercory '+sl[i]);
result := False;
end;
// delete main directory
RemoveDir(dir);
sl.Free;
end;
// how to use function DeleteDirWithFiles
procedure Form1_Button4_OnClick (Sender: string; var Cancel: boolean);
var
sDir: string;
begin
sDir := 'd:\folder';
if not DeleteDirWithFiles(sDir) then
ShowMessage('Can''t remove directory');
end;
Great !
Merci
Pierre Perreault, Canada
My Visual Database → General → Delete Directory with non empty subdirectory and files
Powered by PunBB, supported by Informer Technologies, Inc.
Theme Hydrogen by Kushi