Example Delphi
Delphi Examples Collection
Today, Delphi is one of the popular desktop programming tool. There are thousand even million programmer in this world using delphi as their favorit tool. This site try to collect the examples, tips and tricks of Delphi programming. We collect, test them and redistribute the collection of delphi programming for you.
Delete a Directory
Author: admin | Category: Files, Tips and Tricks, Windows API
//This is how we can delete a directory //DelDir Function originally wrote by Rainer Kümmerle (http://www.thinklazy.de) //Put a Button1(Tbutton) then use this code //Make a directory named 'DeletedDir' in your application path to be tested unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses ShellApi; function DelDir(dir: string): Boolean; var fos: TSHFileOpStruct; begin ZeroMemory(@fos, SizeOf(fos)); with fos do begin wFunc := FO_DELETE; fFlags := FOF_SILENT or FOF_NOCONFIRMATION; pFrom := PChar(dir + #0); end; Result := (0 = ShFileOperation(fos)); end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(ExtractFilePath(Application.ExeName)+'DeletedDir'); if DelDir(ExtractFilePath(Application.ExeName)+'DeletedDir')=true then ShowMessage(ExtractFilePath(Application.ExeName)+'DeletedDir'+' ' + 'succesfully deleted') else ShowMessage('Delete Failed'); end; end.
Post Meta
-
Files, Tips and Tricks, Windows API -
Comments Feed -