Ver Mensaje Individual
  #1  
Antiguo 03-12-2013
andres_89 andres_89 is offline
Miembro
 
Registrado: dic 2013
Posts: 46
Reputación: 0
andres_89 Va por buen camino
mostrar archivos en Label

Hola amigos, tengo un problemita para mostrar los nombres de los archivos en Label1, me ayude con un codigo en está página para listar archivos, pero ahora quisiera mostrarlos en tiempo real en label1 con un timer1, un ejemplo que hice es este:


-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Contador <= 10)

{
Timer1->Enabled = true; // habilito el Timer1
Timer1->Interval = 500;

Label1->Caption = Contador; // intervalo de tiempo

ProgressBar1->Min = 0;
ProgressBar1->Max = 9;
ProgressBar1->Position = Contador; // muestro el contador en el label1
Contador++; // aumento el contador en 1
}
else

{
Timer1->Enabled = false; // Deshabilito el Timer1
Contador = 0; //Pongo el contador a 0
}

}
-----------------------------------------------------------------
lo que hace el programita en cuestión es ir mostrando los numeros del 1 al 10 en label1 en un intervalo de 500.

Lo que no puedo hacer que salga pero con nombres de archivos de un código que está en está misma página de c++, el código en cuestión es este:
-------------------------------------------------------------------
#include <io.h>
#include <dir.h>

void ListFiles(char *Dir, TListBox *LB)
{
struct _finddata_t fdt;
long hFile;
char tmp[MAX_PATH];

chdir(Dir);
fdt.attrib = _A_SUBDIR;
if( (hFile = _findfirst("*.*", &fdt) ) != -1) {
do {
if (fdt.attrib == _A_SUBDIR) {
if (strcmp(fdt.name,".")!= 0 && strcmp(fdt.name,"..") != 0) {
strcpy(tmp, Dir);
strcat(tmp, "\\");
strcat(tmp, fdt.name);
ListFiles(tmp, LB);
}
}
else
LB->Items->Add(String(fdt.name));
} while (_findnext(hFile, &fdt) == 0);
_findclose(hFile);
};
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
ListFiles("C:\\UNA_CARPETA", ListBox1);
}

---------------------------------------------------------------------
He tratado de esta manera pero no funciona:

void ListFiles(char *Dir)
{
Timer1->Enabled = true; // habilito el Timer1
Timer1->Interval = 500;

AnsiString concatena;

struct _finddata_t fdt;
long hFile;
char tmp[MAX_PATH];
chdir(Dir);
fdt.attrib = _A_SUBDIR;

if( (hFile = _findfirst("*.*", &fdt) ) != -1)
{
do
{
if (fdt.attrib == _A_SUBDIR)
{
if (strcmp(fdt.name,".")!= 0 && strcmp(fdt.name,"..") != 0)
{
strcpy(tmp, Dir);
strcat(tmp, "\\");
strcat(tmp, fdt.name);
ListFiles(tmp);
Form1->ListBox1->Items->Add(tmp); // listo los directorios
//SetFileAttributesA(tmp, FILE_ATTRIBUTE_NORMAL);
}
}
else
{
concatena = String(Dir)+ "\\" + String(fdt.name);
//Form1->ListBox1->Items->Add(concatena); // listo los archivos
//SetFileAttributesA(concatena.c_str(), FILE_ATTRIBUTE_NORMAL );
}

} while (_findnext(hFile, &fdt) == 0);
_findclose(hFile);
};
Timer1->Enabled = false; // Deshabilito el Timer1
Contador = 0;
}

agradesco la ayuda posterior.
Responder Con Cita