Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 15-03-2024
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 16
Poder: 0
navbuoy Va por buen camino
Programa para copiar Carpetas etc.

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--;
	 }
	}

  }
//--------------------------------------------------------------------------

Última edición por navbuoy fecha: 15-03-2024 a las 16:57:36.
Responder Con Cita
  #2  
Antiguo 17-03-2024
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Poder: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola a todos,

¡Gracias por compartirlo, navbuoy!
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Copiar Archivos de carpetas compartidas noobdelphi5 API de Windows 4 20-07-2015 20:29:02
Copiar archivos y carpetas con atributos. darkone2k4 Varios 2 15-06-2010 16:41:25
Obtener carpetas especiales de usuario (Ej.- C:\Documents and Settings\All Users\Datos de programa alquimista Trucos 0 30-05-2008 11:33:42
Copiar carpetas??Leer nombres?? samame .NET 5 15-11-2005 23:19:35
Comprimir carpetas para backup en Builder C++ noa C++ Builder 0 29-02-2004 12:59:20


La franja horaria es GMT +2. Ahora son las 09:11:39.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi