×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How can I delete a directory with all its files ????

How can I delete a directory with all its files ????

How can I delete a directory with all its files ????

(OP)
I am trying to delete a directory with all its files but somethings this error appears.

The file can´t be eliminated. System error (1026)
could anybody explain me that this error means???
How can I remove it????

Thi is my code, sometimes works wells, but other the program give me the error (1026).

If I make a directory for instance c:\kk and I use the program, the program works properly but if I make the directory C:\1234 the program can´t delete it and everytime that I have tried it the program give the error (1026) always with this directory.

Anyway, Thanks in advance.

Unit.h

//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TEdit *Nombre;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
AnsiString FicheroBorrar;
bool A;
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Unit.cpp

//---------------------------------------------------------------------------
#include <vcl.h>
#include <Shellapi.h>
#include <Filectrl.hpp>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
A = false;
try{
if(DirectoryExists(Nombre->Text)){ // EL directorio existe.
FicheroBorrar = Nombre->Text;
Form2->ShowModal();
if (A == true) // Se ha pulsado Aceptar
{
SHFILEOPSTRUCT FileOp;
FileOp.hwnd = Application->Handle;
FileOp.wFunc = FO_DELETE;
FileOp.pFrom = Nombre->Text.c_str();
FileOp.pTo = NULL;
FileOp.fFlags = FOF_NOCONFIRMATION;
FileOp.hNameMappings = 0;
FileOp.lpszProgressTitle = NULL;
bool a = SHFileOperation(&FileOp); //Mando a la papelera los datos
A = false;
}
}
}
catch(...){
}
}
//--------------------------------------------

Unit2.cpp

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
extern bool A;
extern AnsiString FicheroBorrar;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
A = true;
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{
Label2->Caption = FicheroBorrar;
}
//---------------------------------------------------------------------------



--------------------------------------------------------------------------------

RE: How can I delete a directory with all its files ????

I don't know if this will help or not. Try using the following:

int OldErrMode; // use to reset error mode to original mode
OldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS); // get original mode

SHFILEOPSTRUCT FileOp;
FileOp.hwnd = Application->Handle;
FileOp.wFunc = FO_DELETE;
FileOp.pFrom = Nombre->Text.c_str();
FileOp.pTo = NULL;
FileOp.fFlags = FOF_NOCONFIRMATION;
FileOp.hNameMappings = 0;
FileOp.lpszProgressTitle = NULL;
bool a = SHFileOperation(&FileOp); //Mando a la papelera los datos
A = false;

int TheError = GetLastError();
// You will need to display the error somehow
SetErrorMode(OldErrMode); // reset error mode


    The error returned by TheError will be a code in WINERROR.H. You may have to do a search for this. I found mine in the CBuilder directory. Hope this helps.

    By the way this came from June 1998 C++ Builder Developer's Journal. www.reisdorph.com

James P. Cottingham
www.ivcusa.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close