Description
This example shows how to create and remove a directory using the Win32 API's functions: CreateDir() and RemoveDir().
CreateDirectory.cpp
CreateDir.h
Copyright © 1997-2002 Rodolfo A. Frino. All rights reserved.
#include <vcl.h>
#pragma hdrstop
#include "CreateDir.h"
//-------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
String Directory = "C:\\_Directory";
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//Set Form parameters
Width = 400;
Height = 400;
Position = poScreenCenter;
Color = (TColor)0x3cfabd4;
//Create Directory Button
TButton* Button1 = new TButton( this );
Button1->Parent = this;
Button1->Top = 50;
Button1->Width = 120;
Button1->Height = 50;
Button1->Left = Width/4 - Button1->Width/2 ;
Button1->Caption = "Create Directory";
Button1->Visible = true;
Button1->Enabled = true;
Button1->OnClick = Button1Click;
//Remove Directory Button
TButton* Button2 = new TButton( this );
Button2->Parent = this;
Button2->Top = 50;
Button2->Width = 120;
Button2->Height = 50;
Button2->Left = Width*3/4 - Button2->Width/2;
Button2->Caption = "Remove Directory";
Button2->Visible = true;
Button2->Enabled = true;
Button2->OnClick = Button2Click;
}
//-------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Win32 API
if ( CreateDir( Directory ) )
{
ShowMessage("Directory " + Directory + " created");
}
else
{
ShowMessage("Error: Cannot create " + Directory + " directory ");
}
}
//-------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
//Win32 API
if ( RemoveDir( Directory ) )
{
ShowMessage("Directory " + Directory + " removed");
}
else
{
ShowMessage("Error: Cannot remove " + Directory + " directory ");
}
}
#ifndef CreateDirH
#define CreateDirH
//-------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//-------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//-------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//-------------------------------------------------------------
#endif