Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   como buscar ficheros recursivamente (https://www.clubdelphi.com/foros/showthread.php?t=69475)

kenychy 20-08-2010 16:24:49

como buscar ficheros recursivamente
 
Hello friends, necesito saber como buscar ficheros recursivamente, sin importar que sea una carpeta del sistema, o que este oculta, vacía, o que los ficheros estén ocultos y que funcione para unidades raíz.

ecfisa 20-08-2010 18:07:49

Hola kenychy.

El tema se trató Aca . Incluye código Delphi, pero se puede traducir sin mucho cambio.

Saludos.

kenychy 20-08-2010 18:15:18

Men, yo no se nada de delphi, por eso te escribo en esteapartado. yo programo en c++ y necesito en codigo en este.

escafandra 20-08-2010 18:39:28

Quizás esto te interese.

Saludos.

kenychy 31-08-2010 15:38:17

Man, ¿no existe una busqueda de ficheros que sea mas rapida?, esta es super lenta

escafandra 31-08-2010 17:49:56

Depende del tamaño del disco... Explorar todo el disco es penoso. Incorpora un Application->ProcessMessages() en el bucle para que no aparente un "cuelgue". También puedes colocar la función en un hilo a parte del principal.

Si sólo quieres buscar ficheros y no listarlos todos, modifica el código para no llenar el StringList con todos los ficheros sino con los que te interesen, ganarás algo en velocidad.


Saludos.

kenychy 31-08-2010 21:43:10

tio, eso ya lo puse en un Thread, pero sigue siendo igual de lento, si has usado el supercopier te daras cuenta de que busca los ficheros a la velocidad de la luz; lo que nesecito es algo como esto. Si me pudieras decir si hay una API, que lo haga de otra forma mas rapida te lo agradeceria mucho......................

kenychy 13-09-2010 17:18:44

Como puedo usar la busqueda del explorador de windows!!
 
Tios, necesiso saber como puedo usar la busqueda del explorador de windows, si esta es una funcion o una dl, y como puedo trabajar conella para buscar archivos en un directorio, las agradeceria mucho su alluda.

kenychy 20-10-2010 21:02:38

hermanos necesito su ayuda en este tema. Gracias por su colaboracion

kenychy 19-11-2010 17:12:40

hola,¿me escuchan?, uno, dos, tres, probando, gracias, gracias. Gracias por su atrencion.... hermanos ayudenme con este tema please.

javier_ecf 20-11-2010 21:54:46

Bueno apesar de lo algo molesto que fue leer tus post (Recomiendo que leas la Guia de estilo),
Encontre cierto codigo que busca recursivamente archivos y carpetas en c++.

Código:

// The next two lines are for VC++ 6.0 compiler.  You should
// delete them if you compile it with a different compiler.
#include "stdafx.h"
#pragma warning(disable: 4786)
#include <io.h>
#include <string>
#include <vector>
#include <list>
#include <iostream>
using namespace std;


// structure to hold a directory and all its filenames.
struct FILELIST
{
    string path;
    vector<string> theList;
};


void TransverseDirectory(string path, list<FILELIST>& theList)
{
    struct _finddatai64_t data;
    // First create the filename that will be use to initialize the find.
    // "*.*" are wild card characters that tells the find function to return a
    // list of all the files and directories.  You can limit this if you wish
    // to just file with specific extensions, for example "*.txt".  If you do that
    // then finder will not return any directory names.
    string fname = path + "\\*.*";
    // start the finder -- on error _findfirsti64() will return -1, otherwise if no
    // error it returns a handle greater than -1.
    long h = _findfirsti64(fname.c_str(),&data);
    if(h >= 0)
    {
        FILELIST thisList;
        // add empty FILELIST structure to the linked list argument
        theList.push_back(thisList);
        // get pointer to the FILELIST just added to the linked list above.
        list<FILELIST>::iterator it = theList.end();
        it--;
        // set current path
        (*it).path = path;
        do {
            if( (data.attrib & _A_SUBDIR) )
            {
                // make sure we skip "." and "..".  Have to use strcmp here because
                // some file names can start with a dot, so just testing for the
                // first dot is not suffient.
                if( strcmp(data.name,".") != 0 &&strcmp(data.name,"..") != 0)
                {
                    // We found a sub-directory, so get the files in it too
                    fname = path + "\\" + data.name;
                    // recursion here!
                    TransverseDirectory(fname,theList);
                }

            }
            else
            {
                // this is just a normal filename.  So just add it to our vector
                (*it).theList.push_back(data.name);

            }
        }while( _findnexti64(h,&data) == 0);
        // close the find handle. 
        _findclose(h);

    }

}

int main(int argc, char* argv[])
{
    list<FILELIST> MyList;
    string path;
    cout << "Enter starting path ... ";
    getline(cin,path);
    TransverseDirectory(path,MyList);
    list<FILELIST>::iterator it;
    // now just display all the files
    for(it = MyList.begin(); it != MyList.end(); it++)
    {
        vector<string>::iterator its;
        for(its = (*it).theList.begin(); its != (*it).theList.end(); its++)
        {
            cout << (*it).path + "\\" + (*its) << endl;
        }

    }
    cin.ignore();
    return 0;
}


kenychy 14-12-2010 17:47:12

gracias hermano, disculpa si te he causado alguna molestia.


La franja horaria es GMT +2. Ahora son las 02:04:13.

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