Exemplo n.º 1
0
bool Directory::enumFiles(EnumFilesHandler& handler, bool deep)
{
    string filename;

    while (nextFile(filename))
    {
        // Skip all files beginning with a period, most importantly, . and ..
        if (filename[0] == '.')
            continue;

        // TODO: optimize this to avoid allocating so many strings
        string pathname = handler.getPath() + string("/") + filename;
        if (IsDirectory(pathname))
        {
            if (deep)
            {
                Directory* dir = OpenDirectory(pathname);
                bool cont = true;

                if (dir != NULL)
                {
                    handler.pushDir(filename);
                    cont = dir->enumFiles(handler, deep);
                    handler.popDir();
                    delete dir;
                }

                if (!cont)
                    return false;
            }
        }
        else
        {
            if (!handler.process(filename))
                return false;
        }
    }

    return true;
}