Hola, bueno hice este programa para una funcion especifica que es que se tome una "pausa" mientras va copiando archivos y carpetas
os dejo el codigo aqui, utilizo los componentes de Alpha Skins controls
Código:
//////////////// Unit1.h////////////////////////////
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "sButton.hpp"
#include "sComboBox.hpp"
#include "sCustomComboEdit.hpp"
#include "sLabel.hpp"
#include "sListBox.hpp"
#include "sMaskEdit.hpp"
#include "sSkinManager.hpp"
#include <Vcl.FileCtrl.hpp>
#include <Vcl.Mask.hpp>
#include "sPanel.hpp"
#include <Vcl.ExtCtrls.hpp>
#include "sMemo.hpp"
#include "sEdit.hpp"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TsSkinManager *sSkinManager1;
TTimer *Timer2;
TsPanel *sPanel1;
TsLabel *sLabel5;
TsLabel *sLabel4;
TsLabel *sLabel3;
TsLabel *sLabel2;
TsLabel *sLabel1;
TsButton *sButton1;
TsComboBox *sComboBox1;
TsButton *sButton2;
TsListBox *sListBox1;
TDirectoryListBox *DirectoryListBox1;
TDirectoryListBox *DirectoryListBox2;
TDriveComboBox *DriveComboBox2;
TDriveComboBox *DriveComboBox1;
TsEdit *sEdit1;
TsButton *sButton3;
TEdit *Edit1;
TsLabel *sLabel6;
void __fastcall sButton1Click(TObject *Sender);
void __fastcall sButton2Click(TObject *Sender);
void __fastcall sComboBox1CloseUp(TObject *Sender);
void __fastcall Timer2Timer(TObject *Sender);
void __fastcall sButton3Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Código:
///////////////////////////////////////////////////////////////////////////////////
////// Unit1.cpp
///////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#include <vcl.h>
#include <iostream>
#include <fstream>
#include <string>
#include <io.h> // Para _mkdir
#include <direct.h> // Para _chdir
#include <stdio.h> // Para printf
#include <windows.h> // Para CopyFile
#include <System.SysUtils.hpp>
namespace fs = std::filesystem;
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "sButton"
#pragma link "sComboBox"
#pragma link "sCustomComboEdit"
#pragma link "sLabel"
#pragma link "sListBox"
#pragma link "sMaskEdit"
#pragma link "sSkinManager"
#pragma link "sPanel"
#pragma link "sMemo"
#pragma link "sEdit"
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString Lista_Origen[500];
AnsiString Lista_Destino[500];
int counter = 0;
int countdown = 120;
int countdown2 = 120;
bool continue_FLAG = false;
void CopyDirectory(const std::string& sourceDir, const std::string& destDir);
void CopyDirectory(const std::string& sourceDir, const std::string& destDir) {
if (!PathFileExistsA(destDir.c_str())) {
SHCreateDirectoryExA(nullptr, destDir.c_str(), nullptr); // Crear la carpeta de destino si no existe
}
WIN32_FIND_DATAA findFileData;
HANDLE hFind = FindFirstFileA((sourceDir + "/*").c_str(), &findFileData);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (strcmp(findFileData.cFileName, ".") != 0 && strcmp(findFileData.cFileName, "..") != 0) {
std::string sourceFile = sourceDir + "/" + findFileData.cFileName;
std::string destFile = destDir + "/" + findFileData.cFileName;
if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
// Si es un directorio, copiar recursivamente sus contenidos
CopyDirectory(sourceFile, destFile);
} else {
// Si es un archivo, copiarlo directamente
CopyFileA(sourceFile.c_str(), destFile.c_str(), FALSE);
}
}
} while (FindNextFileA(hFind, &findFileData));
FindClose(hFind);
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::sButton1Click(TObject *Sender)
{
AnsiString SRC = DirectoryListBox1->Directory;
SRC.Delete(1,3);
Lista_Origen[counter] = DirectoryListBox1->Directory;
Lista_Destino[counter] = DirectoryListBox2->Directory + '\\' + SRC.c_str();
sListBox1->Items->Add(AnsiString(Lista_Origen[counter].c_str()) + " -> " + AnsiString(Lista_Destino[counter].c_str()));
sListBox1->Refresh();
counter++;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::sButton2Click(TObject *Sender)
{
int c=0;
while(c < sListBox1->Items->Count)
{
sListBox1->ItemIndex = c;
countdown2 = countdown;
Edit1->Text = "siguiente archivo procesandose: " + sListBox1->Items[c].Text;
// Crear la carpeta de destino si no existe
if (!PathFileExistsA(Lista_Destino[c].c_str()))
{
SHCreateDirectoryExA(nullptr, Lista_Destino[c].c_str(), nullptr);
}
CopyDirectory(Lista_Origen[c].c_str(), Lista_Destino[c].c_str());
Timer2->Enabled = true;
WAITING:
while(continue_FLAG == false)
{
Application->ProcessMessages();
goto WAITING;
}
++c;
continue_FLAG = false;
}
ShowMessage("Proceso Finalizado.");
Timer2->Enabled = false;
countdown2 = countdown;
sEdit1->Text = countdown2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::sComboBox1CloseUp(TObject *Sender)
{
switch(sComboBox1->ItemIndex)
{
case 0:
countdown = 2 * 60; break;
case 1:
countdown = 3 * 60; break;
case 2:
countdown = 5 * 60; break;
case 3:
countdown = 8 * 60; break;
case 4:
countdown = 10 * 60; break;
case 5:
countdown = 12 * 60; break;
case 6:
countdown = 14 * 60; break;
case 7:
countdown = 15 * 60; break;
case 8:
countdown = 18 * 60; break;
case 9:
countdown = 20 * 60; break;
case 10:
countdown = 25 * 60; break;
case 11:
countdown = 30 * 60; break;
}
countdown2 = countdown;
sEdit1->Text = countdown2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
countdown2 = countdown2 - 1;
sEdit1->Text = countdown2;
if (countdown2 == 0)
{
countdown2 = countdown;
continue_FLAG = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::sButton3Click(TObject *Sender)
{
if(counter > 0)
{
if (counter < 500)
{
sListBox1->Items->Delete(counter-1);
counter--;
}
}
}
//--------------------------------------------------------------------------